【发布时间】:2017-02-20 11:45:56
【问题描述】:
是的,我检查了其他 stackoverflow 结果: C++ initial value of reference to non-const must be an lvalue
错误:非常量引用的初始值必须是左值
呼叫:
Value& c = getConfigValue("test");
功能:
Value* getConfigValue(const char* name) {
if (!cleverconfig_loaded) {
readConfig();
if (!cleverconfig_loaded) {
return NULL;
}
}
if (!cleverconfig.HasMember(name)) {
return NULL;
}
return cleverconfig[name];
}
所以即使我将参数“name”设置为常量值后,它仍然给我这个错误,有谁知道为什么?
【问题讨论】:
-
你的函数
getConfigValue返回一个不能分配给引用的指针。 -
这是什么
cleverconfig? -
getConfigValue正在返回一个Value*并且您想要初始化一个Value&。你的意思是*getConfigValue("test")? -
cleverconfig 是一个“文档”
-
@defube 这当然会在
getConfigValue返回一个空指针时失败。
标签: c++