/*(2)(多重继承)定义一个工人类Worker,
保护数据成员:char name[20];
公有成员: Worker(char s[]);构造函数
void show();输出数据成员信息。
定义一个儿童类Children,
保护数据成员:int age;
公有成员: Children(int a);构造函数
void show1();输出数据成员信息。
定义一个童工类Clabourer,公有继承工人类和儿童类,
私有成员:char hometown[20];
公有成员: Clabourer(char s[], int a,char ht[]);构造函数
void show2();输出数据成员信息。
在主函数中,用童工类创建对象姓名为小明,年龄为14岁,籍贯为A市,并输出童工的信息。
*/
#include <iostream>
#include <string>
using namespace std;
class Worker//工人类
{
protected:
char name[20];
public:
Worker(const char s[])//构造函数
{
strcpy_s(name, s);
}
void show()//输出数据成员信息。
{
cout << "姓名为:" << name << endl;
}
};
class Children
{
protected:
int age;
public:
Children(int a)//构造函数
{
age = a;
}
void show1()//输出数据成员信息
{
cout << "年龄为:" << age << endl;
}
};
class Clabourer :public Worker, Children//童工类
{
private:
char hometown[20];
public:
Clabourer(const char s[], int a, const char ht[]):Worker(name),Children(age)//构造函数
{
strcpy_s(hometown, ht);
}
void show2()// 输出数据成员信息。
{
cout << "姓名:" << name<<endl;
cout << "年龄:" << age << "岁" << endl;
cout << "籍贯:" << hometown << endl;
}
};
int main()
{
Clabourer D("小明", 14, "A市");
D.show2();
return 0;
}
编译器没报错但是出现了这个弹框
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 浪客 2022-05-12 10:49关注
构造参数不对
Clabourer(const char s[], int a, const char ht[]):Worker(s),Children(a)//构造函数本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥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系统搭建请教(跨境电商用途)
- ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。