我必须通过一个boost::shared_ptr
:
boost::shared_ptr<Protobuf::Person::Profile> pProfile =
boost::make_shared<Protobuf::Person::Profile>();
这是 protobuf 的指针,指向 protobuf 的函数oPerson.set_allocated_profile(pProfile)
,但oPerson.set_allocated()
需要一个指向Protobuf::Person::Profile
.
我尝试了几种方法,但我认为当我尝试将 protobuf 对象转换为 JSON 时,使用pbjson::pb2Json
的是基于快速 json 构建的库函数,指针超出范围导致分段错误。
方法一:
oPerson.set_allocated_profile(pProfile.get());
方法二:
oPerson.set_allocated_profile(&*pProfile);