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

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日

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上