【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;
}
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;
}
相关文章推荐
- Cocos2d-x 3.1.1 学习日志3--C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++ 常量数据成员、静态数据成员、常量静态数据成员的初始化
- C++之类内不同的数据成员类型以及方法(静态,const,引用,常量引用)
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++ 常量数据成员、静态数据成员、常量静态数据成员的初始化
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- c++中静态数据成员与常量的初始化
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
- C++之静态数据成员与静态成员函数
- 只有静态常量整型数据成员才可以在类中初始化
- c++ 静态数据成员总结
- C++静态成员(2) - 静态数据成员
- C++_静态数据成员和静态成员函数
- C++静态整型成员数据在类内初始化
- 3-6 静态数据成员与静态成员函数(c++)
- C++:静态成员函数,静态数据成员,成员函数存储方式