|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
Person(int a, char s, string n, string add, int t) :age(a), sex(s), name(n), address(add), telephone(t)
{}
//protected:
int age, telephone;
char sex;
string name, address;
};
class Teacher :virtual public Person
{
public:
string title;
void virtual display();
};
class Cadre :virtual public Person
{
public:
string post;
void virtual display();
};
class Teacher_Cadre :virtual public Teacher, virtual public Cadre
{
public:
int wages;
void show();
};
void Teacher::display()
{
cout << "该教师的年龄,性别,名字,地址,电话号码分别为:" << endl;
cout << age << " " << sex << " " << name << " " << address << " " << telephone << endl;
cout << "该老师的职称为:" << title;
}
void Cadre::display()
{
cout << "该干部的年龄,性别,名字,地址,电话号码分别为:" << endl;
cout << age << " " << sex << " " << name << " " << address << " " << telephone << endl;
cout << "该干部的职务为:" << post;
}
void Teacher_Cadre::show()
{
cout << "该教师兼干部的工资为: " << wages << endl;
}
int main()
{
Person p1(25, 'f', "张红", "湖北大学", 12345);
Teacher t; //t 报错
t.title = "班主任";
t.display();
Cadre c; //c 也报错
c.post = "校长";
c.display();
Teacher_Cadre tc; //tc 报错
tc.wages = 10000;
tc.show();
}
有没有好心人能指点迷津?
|
|