Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proto c++ implementation - "marked ‘override’, but does not override" error

// 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
    }
};

Class InvoiceTemplateMatcher::Service is generated during compile time from that .proto file.

When I try to compile, I get an error

‘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 {

As far as I can tell, my code is written in the same way as in Route Guide example. What am I missing?

like image 872
julka Avatar asked Apr 08 '19 12:04

julka


2 Answers

I know that this post is quite old but I will give a correct answer for any future troubleshoots that person might across while wokring with protobufs.

You are correct saying that the class implementation has been generated automatically and protobuf c++ generation has this class function by default:

virtual ::grpc::Status Process(::grpc::ServerContext* context, const ::orka_engine_internal::InvoiceFilePath* request, ::orka_engine_internal::UploadStatus* response);

So you need to match your function exactly to virtual function. In your example, just change invoicefp to request

like image 83
aikhs Avatar answered Nov 13 '22 05:11

aikhs


Such an error is issued by the compiler when the the function is not marked virtual in the base class.

Consider the following minimal example:

class Base{
    void Foo() {}
};

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

Compiler issues the error:

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

See Demo

The override specifier specifies that a virtual function overrides another virtual function.

like image 14
P.W Avatar answered Nov 13 '22 05:11

P.W