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;
}
【C++】类的静态常量数据成员! static const
最新推荐文章于 2024-07-26 15:15:48 发布