That makes perfect sense---thanks. On Mon, Aug 31, 2009 at 12:36 PM, Kenton Varda <ken...@google.com> wrote:
> The problem is that the parameter binding that you are providing has type > DummyResponse* but the method you are trying to bind takes const > DummyResponse*. Even though the former is implicitly convertible to the > latter, the compiler will not consider this when selecting a template > overload. The solution is to manually cast the pointer to make it const > before calling NewCallback. > > On Sun, Aug 30, 2009 at 9:29 PM, srlindemann <srlindem...@gmail.com>wrote: > >> >> I've been messing with the Service interface in C++ but have hit a few >> bumps with the NewCallback method. Basically, the compiler (g++ 4.2.4 >> on Ubuntu) seems to be unable to match my function call to one of the >> template overloads---it then fails when it tries to match it to the >> void(*)() signature. Is there something here I'm missing? I'm using >> protobuf-2.2.0. >> >> Source (closure_trouble.cpp): >> >> #include <google/protobuf/service.h> >> >> class DummyResponse >> { >> }; >> >> class ClosureTest >> { >> public: >> void MethodWithArg(const DummyResponse* response) {} >> }; >> >> int main(int argc, char* argv[]) >> { >> ClosureTest ct; >> DummyResponse dr; >> >> google::protobuf::Closure* closure = google::protobuf::NewCallback >> (&ct, &ClosureTest::MethodWithArg, &dr); >> return 0; >> } >> >> Command line: >> m...@my-laptop:~/Programming/cpp/protio/protio_main/tests$ g++ -o >> closure_trouble closure_trouble.cpp >> closure_trouble.cpp: In function ‘int main(int, char**)’: >> closure_trouble.cpp:18: error: cannot convert ‘ClosureTest*’ to ‘void >> (*)()’ for argument ‘1’ to ‘google::protobuf::Closure* >> google::protobuf::NewCallback(void (*)())’ >> >> Any thoughts? Thanks. >> >> (P.S. I tried a number of similar variations, such as a function >> instead of a instance method, etc. Couldn't make anything work except >> subclassing Closure.) >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---