I want to pass argv
to another function, and can do it with no problems when I define the function like this:
void function(char** argv);
and call it from main
with:
function(argv);
However, I would like to keep everything const where possible (I don't actually plan to change argv
, or the value of either of the pointers). My problem is that as soon as I add the keyword const anywhere to argv
in the function declaration I get conversion errors, e.g. this code
void function(const char** argv);
gives the compile error:
error: invalid conversion from ‘const char**’ to ‘char* const*’ [-fpermissive]
I've tried putting const in different places and get similar errors. Is there a way to pass argv while keeping the contents and pointers all constant?
std::vector<std::string> arguments(argv + 1, argv + argc);
– Labroidchar* const*
in your code? If yes, please add the corresponding code. Also does this answer help? – Nibchar* const*
in my code – Oinkerror: invalid conversion from ‘char**’ to ‘const char**’ [-fpermissive]
. This may be due to the problem @Nib linked to. – Oinkchar * const argv[]
, so you making your argvconst char **
is incompatible. – Kowalczykint main( int argc, char * const argv[] )
– Company