point cloud tutorial code을 OO 형식으로 리팩토링하려고합니다.PointCloudT :: Ptr 클래스 멤버 초기화
여기 내 계급 구조의
class PclRegister {
private:
// The point clouds we will be using
PointCloudT::Ptr cloud_in; // Original point cloud
PointCloudT::Ptr cloud_tr; // Transformed point cloud
PointCloudT::Ptr cloud_icp; // ICP output point cloud
pcl::console::TicToc time;
public:
void registerFixedSurface(std::string path);
Eigen::Matrix4d applyTransformation();
void performIcp(Eigen::Matrix4d transform, int iterations);
void print4x4Matrix(const Eigen::Matrix4d & matrix);
};
및 사용
내가Assertion failed: (px != 0), function operator*, file /project/build/Boost/install/include/boost/smart_ptr/shared_ptr.hpp, line 704.
내가 내 개인 클래스 멤버가 제대로 초기화하지만 난하지 않는 생각 다음과 같은 런타임 오류가 발생하지만
goicpz::PclRegister pclRegister;
pclRegister.registerFixedSurface(argv[1]);
Eigen::Matrix4d transform = pclRegister.applyTransformation();
pclRegister.performIcp(transform, iterations);
이 문제를 해결하는 방법을 모르겠다. 나는 생성자를 추가하고 거기에서 초기화하려고 시도했다. (이것은 나의 자바 배경이 작동하기 시작한다.)하지만 이것은 합법적 인 것 같지 않다. C++.
나는 모양이 here이고 초기화되지 않은 참조는 컴파일되지 않으며 개체는 암시 적으로 초기화됩니다. 그래서 나는 조금 길다.
누군가 나를 올바른 방향으로 안내 할 수 있습니까?
편집 나는 생성자 당신은 제대로 당신의 shared_ptr을 초기화해야
PclRegister() {
cloud_in = new PointCloudT;
}
error: no viable overloaded '=' cloud_in = new PointCloudT;
을 :
것은 당신이 초기화 또는 아마 당신은이 같은 것을 사용할 수 나중 단계에서 포인터를 업데이트하려면 :: Ptr *은 boost :: shared_ptr *에 기반합니다. 클래스의 생성자에서 명시 적으로 초기화하지 않으면 기본적으로 nullptr로 초기화됩니다. nullptr을 참조 해제하려고하면 표시되는 오류가 발생하므로 사용하기 전에 유효한 포인터를 cloud_ * 변수에 할당해야합니다. –
고마워,하지만 어떻게 생성자에서 초기화합니까? 나는'cloud_ * = new PointCloudT'와'cloud _ * (new PointCloudT)'를 시도했지만 컴파일 오류가 발생한다. – clicky