5_11.cpp

来自「c++案例教程源代码」· C++ 代码 · 共 17 行

CPP
17
字号
#include <iostream> 
using namespace std; 
class FunClass 
{	static int count; 					 //静态数据成员声明
public: 
	FunClass() { count++;    cout << "Constructing object " <<count << endl;   } 
	~FunClass() { cout << "Destroying object " << count << endl;     count--;   } 
	static int GetCount() { return count; } //静态函数成员
}; 
int FunClass::count; 					 //静态数据成员定义
int main() 
{	FunClass a, b, c; 
	cout << "From Class, there are now " << FunClass::GetCount() << " in existence.\n"; 
	cout << "From Object, there are now " << a.GetCount() <<" in existence.\n"; 
	return 0; 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?