// 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
}
};
类 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 {
据我所知,我的代码的编写方式与路由指南示例中的编写方式相同。我错过了什么?
当函数未在基类中标记为virtual
时,编译器会发出此类错误。
请考虑以下最小示例:
class Base{
void Foo() {}
};
class Derived : Base{
void Foo() override {}
};
编译器发出错误:
error: 'void Derived::Foo()' marked 'override', but does not override
void Foo() override {}
查看演示
override
说明符指定一个virtual
函数覆盖另一个virtual
函数。
这篇文章已经很老了,但我会为该人在与 protobufs 一起摇晃时可能遇到的任何未来故障排除给出正确答案。
你说的没错,类实现是自动生成的,protobuf c++ 生成默认具有这个类函数:
virtual ::grpc::Status Process(::grpc::ServerContext* context, const ::orka_engine_internal::InvoiceFilePath* request, ::orka_engine_internal::UploadStatus* response);
因此,您需要将函数与虚函数完全匹配。在您的示例中,只需将invoicefp
更改为request