C++ 函数如下: 这是 Google Protocol Buffers 自动生成的代码。这是用于 .proto 文件中的可变字符串 NodeId。
inline const ::std::string& TestClass::nodeId() const {
return *nodeId_;
上面的函数调用如下
const std::string& NodeId = TestClass.Testconfig().nodeId;
当我编译这个文件时,出现以下错误。
prgms# g++ test.cpp
test.cpp:96:56: error: invalid initialization of reference of type ‘const string& {aka const std::basic_string<char>&}’ from expression of type ‘<unresolved overloaded function type>’
有人能指出我这里有什么问题以及如何解决这个特定错误吗?
最佳答案
你忘了调用函数:
const std::string& NodeId = TestClass.Testconfig().nodeId();
^^
关于c++ - 编译返回字符串 & 的函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130535/