1

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': シンボルは using 宣言では使用できません

編集:「名前空間 google::protobuf; を使用する」場合 関数内では、エラーが発生しなくなりました。私が混乱しているのは、Google の例 (および "The C++ Programming Language" の Stroustrup の例) が示すように機能しないことです。

4

3 に答える 3

4

google::protobufおそらくnamespaceです。この場合、これを行う必要があります。

using namespace google::protobuf;
于 2009-02-26T22:27:54.667 に答える
1

ドキュメントから直接:

Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2873
Error Message
'symbol' : symbol cannot be used in a using-declaration
A using directive is missing a namespace keyword. This causes the compiler to misinterpret the code as a using declaration rather than a using directive.

違いの詳細。

于 2009-02-27T05:21:58.260 に答える