KY90 2021-06-19 22:21 采纳率: 100%
浏览 238
已采纳

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

#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;

}

  • 写回答

2条回答 默认 最新

  • qzjhjxj 2021-06-19 22:38
    关注

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

    #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;
    }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊