xiaoadan2 2022-04-15 22:59 采纳率: 100%
浏览 87
已结题

c++中错误显示无法将参数3从“int”转化为“std::string”;和没有与参数列表匹配的构造函数"Teacher_cadre::Teacher_cadre"实例

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include<iostream>
#include<string>
using namespace std;

class Teacher
{
public:
    Teacher( string name, string sex, string phone, string add,string title, int year) :name(name), sex(sex), phone(phone), add(add), title(title), year(year){}
    void show()
    {
        cout << "name" << name << endl;
        cout << "sex" << sex << endl;
        cout << "year" << year << endl;
        cout << "phone" << phone << endl;
        cout << "add" << add << endl;
        cout << "title" << title << endl;
    }
protected:
    string  name, sex, phone, add, title; int year;
};
class cadre
{
public:
    cadre(string post, string name, string sex, string phone, string add, int year) :name(name),  sex(sex), phone(phone), add(add), post(post), year(year) {}
    void show()
    {
        cout << "name" << name << endl;
        cout << "sex" << sex << endl;
        cout << "year" << year << endl;
        cout << "phone" << phone << endl;
        cout << "add" << add << endl;
        cout << "post" << post << endl;
    }
protected:
    string  name, phone, sex, add, post;  int year;
};
class Teacher_cadre :public Teacher, public cadre
{
public:
    Teacher_cadre( string name, string sex,  string phone, string add, string title, int year, string post, float wage)
        :Teacher(name, sex, phone, add, title ,year), cadre(name, sex, phone, add, post ,year ), wage(wage) {}

    void dispaly()
    {
        Teacher::show();                                            
        cout << post << post << endl;
        cout << wage << wage << endl;

    }
private:
    float wage;         
};
int main()
{
    Teacher_cadre obj("张三","男", 35,"1234561111", "重庆永川", "教授", "院长", 8000);
    
    obj.Teacher::show();
    obj.dispaly();
    return 0;
}


  • 写回答

1条回答 默认 最新

  • HWsir 2022-04-16 00:38
    关注

    你这是定义对象时参数列表不对应,你定义的对象后面的括号里第三个是int 型年龄,但是Teacher_cadre类构造函数你把对应的写到了倒数第三个,传入的参数列表要和定义的对应,不然就会强制类型转换,导致程序出错。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月24日
  • 已采纳回答 4月16日
  • 创建了问题 4月15日

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)