开发者

Const char conversion error

开发者 https://www.devze.com 2023-01-03 23:46 出处:网络
I am getting the following error with gcc. invalid conversion from ‘char**’ to ‘const char**’ With this code.

I am getting the following error with gcc.

invalid conversion from ‘char**’ to ‘const char**’

With this code.

void foo( const int &argc, const char **argv );

int main( int argc, char *开发者_Go百科argv[] )
{
   foo( argc, argv );                                                            
}

Why is this?


When used in function parameter list, char *argv[] declaration is equivalent to char **argv declaration. For this reason, when you are passing argv to foo you are actually attempting to convert argv from char ** type to const char ** type. This is illegal. Read the FAQ http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17 for why it is illegal.

0

精彩评论

暂无评论...
验证码 换一张
取 消