proto c ++实现 - “标记'覆盖',但不覆盖”错误

问题描述 投票:3回答:1
// 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 {

据我所知,我的代码编写方式与Route Guide example相同。我错过了什么?

c++ protocol-buffers grpc
1个回答
1
投票

当函数未在基类中标记为virtual时,编译器会发出这样的错误。

请考虑以下最小示例:

class Base{
    void Foo() {}
};

class Derived : Base{
    void Foo() override {}
};

编译器发出错误:

error: 'void Derived::Foo()' marked 'override', but does not override
     void Foo() override {}

Demo

override说明符指定virtual函数覆盖另一个virtual函数。

© www.soinside.com 2019 - 2024. All rights reserved.