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 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
{
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<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
cout<<"title:"<<title<<endl;
cout<<"wages:"<<wage<<endl;
}
protected:
float wage;
};
int main()
{
Graduate grad("WangSiyang",'B',23,"assistant",90,500000);
grad.show();
return 0;
}