亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我改成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 關注
  • 111 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號