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.
精彩评论