为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我改成Month month3("Jan"); 也不行?

为什么我改成Month month3("Jan"); 也不行?

C++
狐的传说 2023-03-18 14:10:24
char three_let[13][4]={"emp","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};class Month{private:int month;bool check();public:Month(char x[3]); //别的函数我就不写了}Month::Month(char x[3]){int i;for (i=1; i<14; i++) {if ((strcmp(three_let[i], x)==0)) {month=i;break;}}}int main(){Month month3({'J','a','n'});这里总是报错 说no matching constructor for initialization of 'Month'我改成Month month3("Jan"); 也不行说ISO C++11 does not allow conversion from string literal to 'char'
查看完整描述

2 回答

?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

参数不对,“Jan”是个string类型,而你的类里参数类型是指针类型,你可以先char *ch="Jan";然后调用构造函数,Month month3(ch);

查看完整回答
反对 回复 2023-03-21
?
慕标琳琳

TA贡献1830条经验 获得超9个赞

这里总是报错 说no matching constructor for initialization of 'Month' 

是说你没有构造函数。
SO C++11 does not allow conversion from string literal to 'char'

是说不允许从string 到char

查看完整回答
反对 回复 2023-03-21
  • 2 回答
  • 0 关注
  • 86 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号