学习虚拟类的一个例子,自己写一直编译不通过,不知道出什么问题了
#include <iostream>
#include <string.h>
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 public 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,float sco,int a):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<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
cout<<"title:"<<title<<endl;
cout<<"wage:"<<wage<<endl;
}
private:
float wage;
};
int main()
{
Graduate gra1("Yangchong",22,'m',"assisant",98,12000);
gra1.show();
return 0;
}