weixin_50871896
2021-05-18 11:09
采纳率: 100%
浏览 33

有大神帮忙看看这个咋改吗 报错问题是没有参数列表匹配的构造函数实例

#include <iostream>
#include <string>
using namespace std;
class Teacher
{
public:
    Teacher(string nam, char da, string tit, string se)
    {
        name = nam;
        date = da;
        sex = se;
        title = tit;
    }
    void display();
protected:
    string name;
    char date;
    string sex;
    string title;
};
void Teacher::display()
{
    cout << "name: " << name << endl;
    cout << "date: " << date << endl;
    cout << "sex: " << sex << endl;
    cout << "title: " << title << endl;
}
class Cadre
{
public:
    Cadre(string nam, char da, string pos, string se)
    {
        name = nam;
        date = da;
        post = pos;
        sex = se;
    }
    void display1();
protected:
    string name;
    char date;
    string post;
    string sex;
};
void Cadre::display1()
{
    cout << "name: " << name << endl;
    cout << "sex: " << sex << endl;
    cout << "date: " << date << endl;
    cout << "post: " << post << endl;
}
class Teacher_Cadre : public Teacher, public Cadre
{
public:
    Teacher_Cadre(string nam, char da, string sex, string tit, string pos,float w) :Teacher(nam, da, sex, tit), Cadre(nam, da, sex, pos)
    {
        wages = w;
    }
    void show()
    {
        Teacher::display();
        cout << "post:" << Cadre::post << endl;
        cout << "wages:" << wages << endl;
    }
private:
    float wages;
};
int main()
{
    Teacher_Cadre person1("LiHua", 0630, 'm', "professor", "assitant", 9999.9);
    person1.show();
    return 0;
}
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • CSDN专家-cpp_learner 2021-05-18 11:32
    已采纳

    类型对不上呗,你传参需要对应构造函数Teacher_Cadre(string nam, char da, string sex, string tit, string pos, float w)里的参数意义对应才行。

    例如你改成如下就可以了:

    Teacher_Cadre person1("LiHua", 'm', "男", "professor", "assitant", 9999.9);

    这里只是举个例子,具体参数自己填写哈!

    点个采纳吧!

    已采纳该答案
    1 打赏 评论
  • CSDN专家-link 2021-05-18 11:19

    构造函数第二个参数是char类型,你传递的是0630;第三个参数是string,你传递的是字符'm',这自然找不到对应构造函数了

     

    1 打赏 评论
  • 有问必答小助手 2021-05-18 14:19

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    打赏 评论

相关推荐 更多相似问题