c14_01.cpp

来自「这是编程之道C-C++中的源代码,很简练,可以用于相关教学和重新熟悉C-C++时」· C++ 代码 · 共 33 行

CPP
33
字号
#include <iostream >
using namespace std;

class A
{
	static int	m_count;					//声明静态数据成员
public:
	void setcount(int i){m_count = i;}		//设置静态数据成员m_count的值
	void showcount( )						//显示静态数据成员m_count的值
	{
		cout << m_count <<',';  
	}
};

int A::m_count = 0;						//静态数据成员初始化

int main( )
{
	A	a,b;
	a.showcount( );
	b.showcount( );
	
	a.setcount(32);
	a.showcount( );
	b.showcount( );
	
	b.setcount(10);
	a.showcount( );
	b.showcount( );

	return 0;
}

⌨️ 快捷键说明

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