나는 통과 가지고 boost::shared_ptr
:어떻게 protobuf의 boost :: shared_ptr 포인터를 함수에 전달합니까?
oPerson.set_allocated_profile(pProfile)
에, protobuf의 포인터하지만 포인터가
Protobuf::Person::Profile
에
oPerson.set_allocated()
기대
boost::shared_ptr<Protobuf::Person::Profile> pProfile =
boost::make_shared<Protobuf::Person::Profile>();
.
나는 몇 가지 방법을 시도했지만 protobuf 객체를 JSON으로 변환하려고하면 pbjson::pb2Json
은 빠른 json으로 빌드 된 라이브러리 함수이므로 세그먼트 오류가 발생하여 포인터가 범위를 벗어납니다.
방법 1 :
oPerson.set_allocated_profile(pProfile.get());
방법 2 :
oPerson.set_allocated_profile(&*pProfile);
더 컨텍스트없이 도움 : 일생 일대의 당신의 범위를 검토 메모리가 사용 중일 때 여전히 유효한지 확인하십시오. –