一、static成员
声明为static的类成员称为类的静态成员
用static修饰的成员变量,称之为静态成员变量
用static修饰的成员函数,称之为静态成员函数
静态的成员变量一定要在类外进行初始化
#include <iostream>
using namespace std;
class A
{
public:
//构造函数
A(int a = 0)
:_a(a)
{
_sCount++;
}
//拷贝构造
A(const A& a)
:_a(a._a)
{
_sCount++;
}
static int GetCount()
{
return _sCount;
}
private:
int _a;
static int _sCount;
};
//静态成员变量定义
int A::_sCount = 0;
int m