API函数采用类型为'char * const argv []'的参数,我正在c ++应用程序中初始化此类参数,例如:
char* const argv[] = {"--timeout=0", NULL};
并将参数传递给API函数,例如:
Spawner spawner;
spawner.execute (argv, true);
使用g ++编译器,出现以下错误:
error: deprecated conversion from string constant to 'char*' [-Werror=write-strings]
如何摆脱上述错误?
以下是API中execute函数的声明:
void Spawner::execute (char *const argv[], bool bShowChildWindow)
是的,C ++对const字符很烦人(但正确)。尝试这个
char timeoutString[] = "--timeout=0"; // make a non-const char array
char *argv[] = { timeoutString, NULL };
Spawner spawner;
spawner.execute( argv, true );
从技术上讲,问题在于execute
方法的声明,应该是
void Spawner::execute (const char *const argv[], bool bShowChildWindow)
假设execute
不会修改字符串或数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句