Const成员如其它任何成员一样,简单考虑其出现在三个位置:全局作用域、普通函数内部、类里面。
【C++ const成员初始化问题】正面请看测试代码:
#include "stdafx.h"
#include using namespace std;
class A
{
public:
const int j;
//const int k = 3;
const static int i;
};
//const static int A::i = 0;
const int A::i = 1;
//const int j;
int _tmain(int argc, _TCHAR* argv[])
{
//const int i;
cout << A::i << endl;
return 0;
} 下一篇:【阅读悦己】2020年第2本笔记