#include<iostream> #include<string> using namespace std; class Sd { public: string name; static string teacher; static int room; Sd(const string & n):name(n){} void show(){cout<<"我是"<<name<<"在"<<room<<"听"<<teacher<<"老师讲课"<<endl;} static void newTeacher(const string &t){teacher=t;} }; string Sd::teacher="陈"; int Sd::room=300; int main() { Sd s1("伯乐"); Sd s2("哈哈"); Sd s3("陈伟"); s1.show(); s2.show(); s3.show(); Sd::newTeacher("赵");//没有当前对象,没有this指针。 s1.show(); s2.show(); s3.show(); }
时间: 2024-12-17 08:05:21