views:

378

answers:

2

I am trying to use google protobuf and they have the following example:

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;
}

The error I am getting when I try to implement this code in Visual Studio Express 2008 is:

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

Edit: When I do "using namespace google::protobuf;" inside of a function it no longer gives me the error. What I'm confused about is that it doesn't work the way that Google's example (and Stroustrup's in "The C++ Programming Language") seem to indicate.

+1  A: 

google::protobuf is probably a namespace. In this case you need to do this.

using namespace google::protobuf;
Charles Bailey
True, and possibly a bit cleaner in this situation. I wasn't sure if 'SearchService::Stub' needed protobuf qualification, though.
Charles Bailey
true, i wonder about that too. anyway i moved my question as comment to the main question i figured it's better suited there :)
Johannes Schaub - litb
+1  A: 

Directly from the documentation:

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.

More info on the difference.

Andrew Khosravian