Visual Studio 2008 中的 C++ "using"声明

标签 c++ using-declaration

我正在尝试使用 google protobuf,他们有以下示例:

using google::protobuf;

protobuf::RpcChannel* channel;
protobuf::RpcController* controller;
SearchService* service;
SearchRequest request;
SearchResponse response;

void DoSearch() {
  // You provide classes MyRpcChannel and MyRpcController, which implement
  // the abstract interfaces protobuf::RpcChannel and protobuf::RpcController.
  channel = new MyRpcChannel("somehost.example.com:1234");
  controller = new MyRpcController;

  // The protocol compiler generates the SearchService class based on the
  // definition given above.
  service = new SearchService::Stub(channel);

  // Set up the request.
  request.set_query("protocol buffers");

  // Execute the RPC.
  service->Search(controller, request, response, protobuf::NewCallback(&Done));
}

void Done() {
  delete service;
  delete channel;
  delete controller;
}

当我尝试在 Visual Studio Express 2008 中实现此代码时遇到的错误是:

error C2873: 'google::protobuf' : symbol cannot be used in a using-declaration

编辑:当我执行“using namespace google::protobuf;”时在函数内部它不再给我错误。我感到困惑的是,它并不像 Google 的示例(以及 Stroustrup 在“C++ 编程语言”中的示例)所表明的那样工作。

最佳答案

google::protobuf 可能是一个命名空间。在这种情况下,您需要这样做。

using namespace google::protobuf;

关于Visual Studio 2008 中的 C++ "using"声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/592744/

相关文章:

C++ 在成员函数范围内使用语句

c++ - 为什么删除重载时需要使用声明

c++ - std::array 在存储大对象时是否仍然缓存友好?

c++ - 在 Windows 7 的 CodeBlocks 16.01 中构建 glfw3 程序失败

c++ - istream 和 ostream 跨平台

c++ - 带有枚举的 'using' 声明

c++ - Argument-Dependent Lookup 是否在正常范围查找之前进行?

c++ - 在同一个应用程序中使用 Legacy OpenGL 和 Modern OpenGL

c++ - 从 std::istream 读取时,是否有比 reinterpret_cast<char*> 更好的选择?

c++ - clang 没有看到通过 typedef 引入的基类构造函数