#include <iostream>
using namespace std;
class SD207{
public:
string name;
static string teacher;
static int room;
SD207(const string& n):name(n)
{
}
void show()
{
cout << "我是" << name << "在" << room << "教室听" << teacher << "讲课" << endl;
}
};
string SD207::teacher="魏军";
int SD207::room=105;
int main()
{
SD207 p1("伯乐");
SD207 p2("小v");
SD207 p3("小白");
p1.show();
p2.show();
p3.show();
}
//===================================================================
#include <iostream>
using namespace std;
class SD207{
public:
string name;
static string teacher;
static int room;
SD207(const string& n):name(n)
{
}
void show()
{
cout << "我是" << name << "在" << room << "教室听" << teacher << "讲课" << endl;
}
static void new_teacher(const string& t)
{
teacher = t;
}
};
string SD207::teacher="魏军";
int SD207::room=105;
int main()
{
SD207 p1("伯乐");
SD207 p2("小v");
SD207 p3("小白");
p1.show();
p2.show();
p3.show();
SD207::new_teacher("小明"); //
p1.show();
p2.show();
p3.show();
}
静态成员变量和静态成员函数 static
最新推荐文章于 2023-06-02 11:04:41 发布