c++在线请教,为什么会出现这个问题??求解答!
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
Person(string nam, char s, int a)
{
name = nam; sex = s; age = a;
}
protected:
string name;
char sex;
int age;
};
class teacher :virtual Person
{
public:
teacher(string nam,char s,int a,string t):Person(nam,s,a)
{
title = t;
}
protected:
string title;
};
class student :virtual public Person
{
public:
student(string nam, char s, int a, float sco) :Person(nam, s, a)
{
score = sco;
}
protected:
float score;
};
class graduate :public teacher, public student
{
public:
graduate(string nam, char s, int a, string t, float sco, float w) :Person(nam, s, a), teacher(nam, s, a, t), student(nam, s, a, sco)
{
wage = w;
}
void show()
{
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
cout << "age:" << age << endl;
cout << "title:" << title << endl;
cout << "score:" << score << endl;
cout << "wage:" << wage << endl;
}
private:
float wage;
};
int main()
{
graduate grad1("WANG_LI","f", 24, "assistant", 89.5, 1200);
grad1.show();
return 0;
}