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

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

#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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)