c++ - Unglobalising a namespaced class without editing the header -


google provide protobuf template messages send ad exchange network. (available freely here) use protoc turn template c++ code (autogenerated). have problem 1 of classes' names clashes 1 defined me, like

#include "realtime-bidding.pb.h"  // g++ complains bidrequest ambiguous. void bidrequest::fromgoogle(const std::string& protobuf) {     // want write:     // google::bidrequest r;     // r.parsefromstring(protobuf);     if (r.has_field())     {         this->field = r.field();     } } 

i unable without editing files auto-generated protoc (not we'll have each time .proto file changed), , cannot figure out way through use of namespaces.

what real issue google insist of classes in global namespace, e.g.

// realtime-bidding.pb.h class bidrequest_mobile : public ::google::protobuf::message {     inline ::bidrequest_mobile_deviceosversion* mutable_os_version();`.            ^^ } 

so cannot like

namespace google { #include "realtime-bidding.pb.h" } 

as it'll stop auto-generated code compiling.

namespacing code mean far many changes very, large codebase, although correct solution. however, am.

is there trick work without editing autogenerated files? there reason why of classes put global namespace?

you can use package in .proto files.

https://developers.google.com/protocol-buffers/docs/proto#packages


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -