目录
案例1
#include <iostream>
using namespace std;
class test{
private:
int n;
public:
test(int i){
n=i;
cout<<"构造:"<<i<<endl;
}
~test(){
cout<<"析构:"<<n<<endl;
}
int getn(){return n;}
void inc(){++n;}
};
void main()
{
cout<<"循环开始:"<<endl;
for(int i=0;i<3;i++)
{
static test a(3);
test b(3);
a.inc();
b.inc();
cout<<"a.n= "<<a.getn()<<endl;
cout<<"b.n= "<<b.getn()<<endl;
}
cout<<"循环结束"<<endl;
cout<<"退出主程序"<<endl;
}