C++ C++&引用;使用;Visual Studio 2008中的声明

C++ C++&引用;使用;Visual Studio 2008中的声明,c++,using-declaration,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 MyRpcChanne

我尝试使用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中实现此代码时遇到的错误是:

错误C2873:'google::protobuf': 符号不能在一个应用程序中使用 使用声明


编辑:当我在函数内部执行“使用名称空间google::protobuf;”时,它不再给出错误。我困惑的是,它的工作方式与谷歌的例子(以及Stroustrup在C++编程语言中)似乎不一样。

< P> <代码>谷歌:原Buff可能是<代码>命名空间< /代码>。在这种情况下,您需要这样做

using namespace google::protobuf;

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

using namespace google::protobuf;
直接从:

直接从:

(1)根据微软的说法,C2873意味着:

“符号”:符号不能在using声明中使用using指令缺少命名空间关键字。这会导致编译器将代码误解为using声明,而不是using指令

(2) 同样,当我使用C2873和C2039时(我试图在VisualStudio2010中合并CEF3和Cinder),不知何故,我通过更改属性->配置属性->C/C++->代码生成绕过了这两个错误

启用最小重建:是(/GM),启用C++异常:是(/EHSC),启用函数级链接:空< /P> < P>(1),根据微软,C228表示; “符号”:符号不能在using声明中使用using指令缺少命名空间关键字。这会导致编译器将代码误解为using声明,而不是using指令

(2) 同样,当我使用C2873和C2039时(我试图在VisualStudio2010中合并CEF3和Cinder),不知何故,我通过更改属性->配置属性->C/C++->代码生成绕过了这两个错误


启用最小重建:是(/GM),启用C++异常:是(/EHSC),使函数级链接:空

你能引用谷歌例子或你正在跟随的Tc++PL的部分吗?或者你可能是命名空间原动机=谷歌::我熟悉的Google示例()只在namespace std上有一个using声明。您可以参考Google示例或您正在关注的TC++PL部分吗?或者您可能指的是namespace protobuf=Google::protobuf?我熟悉的Google示例()只有一个关于名称空间std.True的using声明,在这种情况下可能更干净一些。不过,我不确定“SearchService::Stub”是否需要protobuf资格认证。不管怎样,我把我的问题作为评论转移到了主要问题上,我认为它更适合这里:)是的,在这种情况下可能更干净一点。不过,我不确定“SearchService::Stub”是否需要protobuf资格认证。无论如何,我把我的问题作为评论转移到了主要问题上,我认为这更适合这里:)