问题
填空题
下列程序的输出结果是 【11】 。
#include <iostream>
using namespace std;
class Test
public:
Test() cnt++;
~Test() cnt--;
static int Count() (return cnt;
private:
static int cnt;
;
int Test::cnt=0;
int main()
cout<<Test::Count()<<’’;
Test t1, t2;
Test *pT3=new Test;
Test *pT4=new Test;
cout<<Test::Count()<<’’;
delete pT4;
delete pT3;
cout<<Test::Count()<<end 1;
return 0;
答案
参考答案:D
解析: static 是局部静态变量,始终存在,实例化一个类就增加1。