源程序:
#include <iostream>
using namespace std;
int time=0,end=0;
class Test
{
public:
Test()
{
if(time==0) //程序填空
cout<<"欢迎使用测试程序!"<<endl;
time=time+1;
}
~Test()
{
end=end+1;
if(end==time)
cout<<"下次再见!"<<endl;
}
void print()
{
cout<<"共生成过"<<time<<"个对象"<<endl; //程序填空
}
};
void main()
{
Test obj1,obj2,obj3;
obj1.print();
}
结果: