【C++】类的静态常量数据成员! static const

VC++ 2005 和 VC++ 6.0 情况如下:

1 VC++ 2005

//ProjectAClass.h
#ifndef PROJECT_A_CLASS_HPP
#define PROJECT_A_CLASS_HPP

class ProjectAClass
{
public:
    ProjectAClass(void);
    ~ProjectAClass(void);

   
static const int SIZE_PROJECT_A = 100;
    static const double MAX_A;


    void DisplayProjectA(void);
};

#endif

//ProjectAClass.cpp
#include "StdAfx.h"
#include "ProjectAClass.h"
#include <iostream>

//const int ProjectAClass::SIZE_PROJECT_A;
const double ProjectAClass::MAX_A = 100.012;

ProjectAClass::ProjectAClass(void)
{
}

ProjectAClass::~ProjectAClass(void)
{
}

void ProjectAClass::DisplayProjectA(void)
{
    std::cout << "Class static const Data : int SIZE_PROJECT_A = " << SIZE_PROJECT_A << std::endl;
    std::cout << "Class static const Data : double MAX_A       = " << MAX_A << std::endl;
}

2 VC++ 6.0

//Ex.h
#ifndef EX_HH
#define EX_HH

class Ex
{
public:
    Ex();
   
static const int MAX;
    static const double MIN;


    void DisplayEx();
};

#endif

//Ex.cpp
#include "stdafx.h"
#include "Ex.h"
#include <iostream.h>

const int Ex::MAX = 100;
const double Ex::MIN = 100.012;


Ex::Ex()
{
}

void Ex::DisplayEx()
{
    cout << "Class static const Data : int MAX    = " << MAX << endl;
    cout << "Class static const Data : double MIN = " << MIN << endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值