I'm trying to return a pointer to a pointer from a function.
I have the following function
char **foo() {
const char **bar;
...
return bar;
}
and I get the following warning:
warning: return from incompatible pointer type [enabled by default]
what am I missing?
You can't jsut cast away the const qualifier like that. It points to pointers to const chars. You can however:
const char **foo() {
const char **bar;
...
return bar;
}
bar
被声明为const char **
但是您将返回char **
这是因为函数foo
返回char **
,而bar
是const char **
类型。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.