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

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'

狐的传说
浏览 188回答 2
2回答

幕布斯6054654

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

慕标琳琳

这里总是报错 说no matching constructor for initialization of 'Month'&nbsp;是说你没有构造函数。SO C++11 does not allow conversion from string literal to 'char'是说不允许从string 到char
打开App,查看更多内容
随时随地看视频慕课网APP