问题
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?
来源:https://stackoverflow.com/questions/25386698/passing-argv-as-const