C++ 初始化PointCloudT::Ptr类成员

C++ 初始化PointCloudT::Ptr类成员,c++,shared-ptr,point-cloud-library,C++,Shared Ptr,Point Cloud Library,我正在尝试将其重构为OO形式 这是我的班级结构 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 ou

我正在尝试将其重构为OO形式

这是我的班级结构

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);
};
用法

goicpz::PclRegister pclRegister;
pclRegister.registerFixedSurface(argv[1]);
Eigen::Matrix4d transform = pclRegister.applyTransformation();
pclRegister.performIcp(transform, iterations);
但是,我得到以下运行时错误

Assertion failed: (px != 0), function operator*, file /project/build/Boost/install/include/boost/smart_ptr/shared_ptr.hpp, line 704.
我相信我的私人班级成员没有正确初始化,但我不知道如何解决这个问题。我尝试添加一个构造函数并在那里初始化它们(这是我的java背景开始发挥作用),但这似乎不是合法C++。 我看了一下,它说未初始化的引用将不会编译,并且对象是隐式初始化的。所以我有点迷路了

有人能给我指出正确的方向吗

编辑

我试过构造器

PclRegister() {
    cloud_in = new PointCloudT;
}
error: no viable overloaded '=' cloud_in = new PointCloudT;

您必须正确初始化共享的\u ptr。如果可以在构造函数中执行此操作,请按如下方式执行:

PclRegister()
  : cloud_in(new PointCloudT),
    cloud_tr(new PointCloudT),
    cloud_icp(new PointCloudT)
{}
如果您想在以后的阶段初始化或更新指针,您可能会使用以下方法:

cloud_in = PointCloudT::Ptr(new PointCloudT)

PointCloudT::Ptr基于boost::shared\u Ptr。如果您没有在类的构造函数中显式地初始化它们,那么默认情况下它们被初始化为null ptr。如果您尝试取消对nullptr的引用,您将看到错误,因此请确保在使用之前为您的cloud_*变量分配了有效指针。谢谢,但是如何在构造函数中初始化?我尝试了
cloud.*=new PointCloudT
cloud.*(new PointCloudT)
,但两者都给出了编译错误。