#include<iostream.h>
class teach
{private:
static int counter;
int id;
public:
teach();
void show();
static void setcounter(int);
};
int teach::counter=1;//静态数据成员初始化
teach::teach()
{id=counter++;;
}
void teach::show()
{cout<<id<<endl;
}
void teach::setcounter(int new_counter)
{counter=new_counter;
}
int main()
{teach s1;
s1.show();
teach s2;
s2.show();
teach s3;
s3.show();
s1.setcounter(10);//重新设置计数器
teach s4;
s4.show();
teach s5;
s5.show();
return 0;
}