c++错误error C2661: 'Person::Person' : no overloaded function takes 4 parameters

class Person
{
public:
Person(int identity,string name,int sx, int yw,int jbgz,int glgz,int bt)
{
m_identity = identity;
m_name = name;
m_sx = sx;
m_yw = yw;
m_jbgz=jbgz;
m_glgz=glgz;
m_bt=bt;
}
virtual void Display() = 0;
protected:
int m_identity;
string m_name;
int m_sx;
int m_yw;
int m_jbgz;
int m_glgz;
int m_bt;
};
class Student: public Person
{
public:
Student(int identity,string name,int sx,int yw):Person(identity, name, sx, yw){}
void Display()
{
cout << "学号:"<< m_identity << endl;
cout << "姓名:" << m_name << endl;
cout << "数学:" << m_sx << endl;
cout << "语文:" << m_yw << endl;
cout << "总成绩: " << m_sx+m_yw << endl << endl;
}
};
下面是主程序:
void main()
{
Student student(1,"Tom",50,60);
Zhiyuan zhiyuan(2,"Andy",1000,500);
Teacher teacher(3,"Douglas",1500,500);
HeterList<Person> myList;
//加入链表
myList.Insert(&student);
myList.Insert(&zhiyuan);
myList.Insert(&teacher);
myList.Print();
//逐个删除
myList.Delete();
myList.Delete();
myList.Delete();
myList.Print();
}老是出现那个错误,怎么改

Student(int identity,string name,int sx,int yw):Person(identity, name, sx, yw){}
你的person构造函数的参数有很多个,这里只调用了4个,错误就是这个。追问

一定要全部调用完吗,不能只调用其中几个吗,我下面还有别的派生类需要用到另外几个参数,那该怎么办

追答

必须完全按参数列表来,你可以重载几个参数不一样的构造函数

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答