我正在尝试使用 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/