Error c2440: cannot convert const char[4] to char*

◇◆丶佛笑我妖孽 提交于 2019-12-11 15:26:41

问题


i have a question:

I have a code in QT Creator (build in MSVC2013) that first work perfectly, now in other computer with an updated QT Creator (build in MSVC2015) when try tu rungive me this error:

"error: C2664: 'wave_object wave_init(char *)': cannot convert argument 1 from 'const char [4]' to 'char *'" "Conversion from string literal loses const qualifier (see /Zc:strictStrings)"

Error is in this part of the code:

wave_object db4;                            
wt_object wt;
db4 = wave_init("db4");                     
wt = wt_init(db4, "dwt", N, 4);            
setDWTExtension(wt, "sym");
setWTConv(wt, "direct");

The definition of the method is here:

wave_object wave_init(char* wname) {
wave_object obj = NULL;
int retval;
retval = 0;

if (wname != NULL) {
    retval = filtlength(wname);
}

I compile this with MinGW and dont have error, in the computer with QT Creator builded with MSVC2013 work fine also with the MSVC2013 compiler but now with the QT Creator builded with MSVC2015 appears this error with the MSVC2015 compiler.

I need to use the same compiler that was builded QT Creator because I am using QWT Plugins and is necessary to use the same compiler.

Thank you for your help! =)


回答1:


In your function call:

db4 = wave_init("db4"); 

The "db4" argument is string literal, and is in a strict sense const.

Your definition of the function:

wave_object wave_init(char* wname)

does not identify parameter wname as const.

Modify as follows:

wave_object wave_init(const char* wname)


来源:https://stackoverflow.com/questions/48134161/error-c2440-cannot-convert-const-char4-to-char

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!