WSS_ 2020-04-04 14:24 采纳率: 37.5%
浏览 4257
已采纳

为什么会出现[Error] no matching function for call to 'Student::Student()'???

#include
#include
#pragma warning(disable:4996)
using namespace std;

class Person

{

protected:
char name[10];

char sex;
public:
Person(const char name[], char sex) :sex(sex)

{

    strcpy(this->name, name);

}

};

class DoubleArray

{

protected:

double score;

public:

DoubleArray(double score) :score(score) {}
DoubleArray(DoubleArray &a)

{

    score=a.score;
} 
void print() const
{

    cout << score;

}
int operator-()// 重载取反运算符 operator-,使Student类中的cheat函数可正确运行 

{

    return -score;

} 

};

class Student : public Person

{

private:

int id;
char name[20];
DoubleArray score;

public:
static int count;
~Student()
{

    count--; 

}

void cheat(DoubleArray& ds) 
{ 

    score = -ds; 

} // 若作弊,则分数为负
Student(Student &s,DoubleArray& sc);
Student(int id, const char* name, char sex, DoubleArray& sc);
Student(int id, const char* name, char sex, double ds);
void disp();

};
Student::Student(int id, const char* name, char sex, DoubleArray& sc):Person(name,sex),score(sc)
{

count+=1;

}
Student::Student(int id, const char* name, char sex, double ds):Person(name,sex),score(ds)
{

count+=1;

}
void Student::disp()
{

cout<<"(id, name, sex, score)="<<"("<<id<<","<<name<<","<<sex<<",";
score.print();
cout<<")"<<endl;

}
// 类外实现Student类的成员函数,令main函数得以正确运行并输出相应的结果
int main()
{

cout << "count=" << Student::count << endl;
DoubleArray sc(97);
Student s[3]={Student(1,"Ann",'F',sc),Student(2,"Mike",'M',79),Student(3,"Lucy",'F',sc)};
s[2].cheat(sc);
for (int i = 0; i < 3; i++)
s[i].disp();
cout << "count=" << Student::count << endl;
return 0;

}

  • 写回答

2条回答 默认 最新

  • meehotel 2020-04-06 15:08
    关注

    解决办法:删除DoubleArray的拷贝构造函数。

    同Xcode警告 !No matching constructor for initialization of 'Student'同问啊!为什么说** 没有用于初始化“Student”的匹配构造函数**
    图片说明
    (宁也是大车埋土学校的?
    btw说一个小问题你的两个student构造函数id没初始化 id(id)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题