您的位置:首页 > 编程语言 > C语言/C++

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

2009-02-26 14:07 363 查看
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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: