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 關注
- 111 瀏覽
添加回答
舉報
0/150
提交
取消