jul*_*lka 11 c++ protocol-buffers grpc
// api_internal.proto
service InvoiceTemplateMatcher {
rpc Process(InvoiceFilePath) returns (UploadStatus) {}
}
message InvoiceFilePath {
string invoice_id = 1;
string file_path = 2;
}
// template_matcher/src/main.cc
class OrkaEngineInvoiceTemplateMatcherImpl final : public InvoiceTemplateMatcher::Service {
private:
Status Process(
ServerContext* context,
orka_engine_internal::InvoiceFilePath* invoicefp,
orka_engine_internal::UploadStatus* response) override {
// do stuff
}
};
Run Code Online (Sandbox Code Playgroud)
类InvoiceTemplateMatcher::Service是在编译期间从该.proto文件生成的。
当我尝试编译时,出现错误
‘grpc::Status OrkaEngineInvoiceTemplateMatcherImpl::Process(grpc::ServerContext*, orka_engine_internal::InvoiceFilePath*, orka_engine_internal::UploadStatus*)’ marked ‘override’, but does not override
Status Process(ServerContext* context, orka_engine_internal::InvoiceFilePath* invoicefp, orka_engine_internal::UploadStatus* response) override {
Run Code Online (Sandbox Code Playgroud)
据我所知,我的代码与Route Guide example 中的编写方式相同。我错过了什么?
P.W*_*P.W 12
当函数未virtual在基类中标记时,编译器会发出此类错误。
考虑以下最小示例:
class Base{
void Foo() {}
};
class Derived : Base{
void Foo() override {}
};
Run Code Online (Sandbox Code Playgroud)
编译器发出错误:
error: 'void Derived::Foo()' marked 'override', but does not override
void Foo() override {}
Run Code Online (Sandbox Code Playgroud)
看演示
该override符指定一个virtual功能覆盖其他virtual功能。
我知道这篇文章已经很老了,但我会为人们在使用 protobuf 时可能遇到的任何未来故障提供正确的答案。
你说得对,类实现是自动生成的,protobuf c++ 生成默认有这个类函数:
virtual ::grpc::Status Process(::grpc::ServerContext* context, const ::orka_engine_internal::InvoiceFilePath* request, ::orka_engine_internal::UploadStatus* response);
Run Code Online (Sandbox Code Playgroud)
所以你需要将你的函数与虚函数完全匹配。在你的例子中,只需更改invoicefp为request
| 归档时间: |
|
| 查看次数: |
25287 次 |
| 最近记录: |