2

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 *argv[] )
{
   foo( argc, argv );                                                            
}

Why is this?

Thomas
  • 2,939
  • 6
  • 32
  • 29

1 Answers1

8

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.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765