没有与参数列表匹配的构造函数

#include<iostream>

#include<string.h>

using namespace std;

class Person {

public:

Person() {}

Person(const char* name, int id){

this->id = id;

strcpy_s(this->name, 81, name); }

~Person() {};

 

谁能帮我看看是哪里有问题吗?

void Display() {

cout << name << " " << id << " " << endl; }

protected:

char name[81];

int id;

};

class CollegeStu:public Person {

public:

CollegeStu() {}

CollegeStu(const char* major,double score):Person(name,id)

{ this->score =score ;

strcpy_s(this->major, 81, major);

void Display() {

cout <<name<<" "<<id<<" "<< major << " " << score << endl;

}

private:

char major[81];

double score;

};

int main()

{

char name[81], major[81];

int id;

double score;

cin >> name >> id >> major >> score;

CollegeStu cs(name, id, major, score);

cs.Display();

return 0;

}

修改如下,供参考,望采纳:

#include<iostream>

#include<string.h>

using namespace std;

class Person {
public:

       Person() {}

       Person(const char* name, int id){
               this->id = id;
              strcpy(this->name, name);
       }

       ~Person() {};
       //谁能帮我看看是哪里有问题吗?

       void Display() {
           cout << name << " " << id << " " << endl;
       }

protected:

       char name[81];
       int id;
};

class CollegeStu:public Person {
public:

      CollegeStu() {}
      CollegeStu(const char *name,int id,const char* major,double score):Person(name,id)
      {
           this->score =score ;
           strcpy(this->major, major);
      }

      void Display() {
           cout <<name<<" "<<id<<" "<< major << " " << score << endl;
      }

private:

      char   major[81];
      double score;
};

int main()

{
    char name[81], major[81];
    int  id;
    double score;
    cin >> name >> id >> major >> score;
    CollegeStu cs(name, id, major, score);
    cs.Display();
    
    return 0;
}

 

CollegeStu的构造函数只声明了3个参数,而在main函数里创建CollegeStu对象的时候却传了4个参数。