这个运行结果为啥是2呢
//有如下类定义及类应用,试问,该程序输出为____
class CStudent
{
int sno;
public:
static int stuCount;
CStudent(int sno):sno(sno) { stuCount++;}
~CStudent(){}
};
int CStudent::stuCount=0;
int main()
{
CStudent stu1(1);
CStudent *pstu=new CStudent(2);
cout<<stu1.stuCount;
}
因为stuCount是静态的(相当于全局变量),所以每次调用构造函数,都会++