我正在尝试使用 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 的示例(以及 Stroustrup 在“C++ 编程语言”中的示例)似乎表明的那样工作。