继承的问题,求助!!
#include"iostream"#include"string"
using namespace std;
class Person
{ public:
Person(string n,string s,int a)
{name=n;sex=s;age=a;}
void display()
{ cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"年龄:"<<age<<endl;
}
protected:
string name;
string sex;
int age;
};
class Teacher:virtual public Person
{ public:
Teacher(string n,string s,int a,string t,string l)
:Person(n,s,a)
{ title=t;
lesson=l;
}
void display()
{ Person::display();
cout<<"职称:"<<title<<endl;
cout<<"担任课程:"<<lesson<<endl;
}
protected:
string title;
string lesson;
};
class Student:virtual public Person
{ public:
Student(string n,string s,int a,string no,string d)
:Person(n,s,a)
{ num=no;
depa=d;
}
void display()
{ Person::display();
cout<<"学号:"<<num<<endl;
cout<<"系别"<<depa<<endl;
}
protected:
string num;
string depa;
};
class Graduate:public Student
{
public:
Graduate(string n,string s,int a,string no,string d,string tn)
:Person(n,s,a),Student(n,s,a,no,d)
{ tname=tn;
}
void display()
{ Student::display();
cout<<"导师:"<<tname<<endl;
}
private:
string tname;
};
int main()
{ Teacher teac("黄奕","女","教授",48,"面向对象程序设计");//报错了。是怎么回事
Student stud("罗志祥","男",18,"2007082011","计算机");
Graduate grad("贺军翔","男",24,"2004082011","计算机系","胡歌");
cout<<"教师的有关数据如下:"<<endl;
teac.display();
cout<<"\n学生的有关数据如下:"<<endl;
stud.display ();
cout<<"\n研究生的有关数据如下:"<<endl;
grad.display();
return 0;
}
E:\VC++\8.cpp(65) : error C2664: '__thiscall Teacher::Teacher(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,class s
td::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)' : cannot convert parameter 3 from 'char [5]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
执行 cl.exe 时出错.