填空题
下列程序的输出结果是{{U}} 【11】 {{/U}}。
#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;
}
【正确答案】
1、4
【答案解析】[解析] static 是局部静态变量,始终存在,实例化一个类就增加1。