[英]Invalid initialization of non-const reference to type from a temporary of type
[英]c++: “invalid initialization of non-const reference of type ‘List&’ from a temporary of type ‘List*’”
我有以下功能设置,可将文件解析为List类设置。 我收到“从类型为“列表*”的临时类型无效地初始化类型为“ List&”的非常量引用”错误。 这是什么意思?
void parseFile (string filename, List& list)
{
ifstream file (filename);
// Parsing code
file.close();
return;
}
int main ()
{
List list;
parseFile ("file.xml", &list); // ERROR OCCURS HERE
return 1;
}
错误消息没有比这更清楚的了。 您要将list
的地址( List*
)传递给声明为采用左值引用( List&
)的函数。
编写parseFile ("file.xml", list);
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.