c++ - 编译返回字符串 & 的函数的问题

标签 c++ string protocol-buffers

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/

相关文章:

c++ - 为什么循环摘要在 gprof 的调用图输出中没有任何调用者?

c - 从函数返回 char[]/string

php - MySQL语法错误将php字符串插入表中

protocol-buffers - 如何打印出 protobuf 消息中的值

c++ - Xercesc XPath 功能

c++ - 二叉搜索树重载 == 运算符或只需要一般建议

c++ - 将用户定义的类型(结构)与容器类(如 set)一起使用

c# - 渲染特殊字符 C#

java - 使用Google Protocol Buffer的简单java文件编译错误

c++ - 是否可以在没有 pthread 的情况下构建 protobuf?