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);

慕标琳琳
TA贡献1830条经验 获得超9个赞
这里总是报错 说no matching constructor for initialization of 'Month'
是说你没有构造函数。
SO C++11 does not allow conversion from string literal to 'char'
是说不允许从string 到char
- 2 回答
- 0 关注
- 86 浏览
添加回答
举报
0/150
提交
取消