Passing argv as const [duplicate]

六眼飞鱼酱① 提交于 2019-12-24 02:22:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!