13
// 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?

julka
  • 1,172
  • 2
  • 13
  • 29
  • what is `InvoiceTemplateMatcher::Service` ? does it really have a `orka_engine_internal::UploadStatus* response)` ? – 463035818_is_not_an_ai Apr 08 '19 at 12:49
  • That class is automatically generated by protoc, that is called by cmake. It should have that as until I messed with service description, everything worked, but I don't see it on my filesystem. – julka Apr 08 '19 at 12:53
  • even if autogenerated you can look at the generated code, no? – 463035818_is_not_an_ai Apr 08 '19 at 12:54
  • I don't see it. find / -name "orka_engine_internal.grpc.pb.h" found nothing. I lacked plugins to manually generate the base classes to inspect them, off to try that now. – julka Apr 08 '19 at 13:12

2 Answers2

15

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.

P.W
  • 26,289
  • 6
  • 39
  • 76
  • Here, base class is automatically generated during compilation from .proto file; I don't really have a control over that. Could it also be a signature mismatch? – julka Apr 08 '19 at 13:00
  • What about derived class? Is it also generated? – P.W Apr 08 '19 at 13:05
  • No, the OrkaEngineInvoiceTemplateMatcherImpl is what I write. – julka Apr 08 '19 at 13:07
  • 2
    Just to register another reason for this error, my function was marked as virtual in the base class, but the **signature** of that function in the derived class was not the same as in the base class. That was not easy to perceive because of many typedefs in the derived class. – axell-brendow Aug 07 '19 at 11:58
5

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

aikhs
  • 949
  • 2
  • 8
  • 20