I have to pass a boost::shared_ptr
:
boost::shared_ptr<Protobuf::Person::Profile> pProfile =
boost::make_shared<Protobuf::Person::Profile>();
which is protobuf's pointer, to a protobuf's function oPerson.set_allocated_profile(pProfile)
but oPerson.set_allocated()
expects a pointer to Protobuf::Person::Profile
.
I have tried couple of ways but I think when I try to convert protobuf object to JSON using pbjson::pb2Json
which is a library function built on rapid json, the pointer goes out of scope causing segmentation fault.
Method 1:
oPerson.set_allocated_profile(pProfile.get());
Method 2:
oPerson.set_allocated_profile(&*pProfile);