point cloud tutorial codeをOO形式にリファクタリングしようとしています。Initialize PointCloudT :: Ptrクラスメンバ
ここで私は私のクラスの構造は、私は、次のランタイムエラー
Assertion failed: (px != 0), function operator*, file /project/build/Boost/install/include/boost/smart_ptr/shared_ptr.hpp, line 704.
を取得しかし、私は私のプライベートクラスメンバーが正しく初期化されていないと信じて
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);
だけどこれを修正する方法がわかりません。コンストラクタを追加してそこに初期化しようとしましたが(これは私のJavaの背景です)、合法的なC++ではないようです。
私は外観がhereであり、初期化されていない参照はコンパイルされず、オブジェクトは暗黙的に初期化されると言います。だから私は少し失われている。
誰かが正しい方向に向かうことができますか?
編集
私はあなたが正しくあなたのshared_ptrを初期化する必要があり、コンストラクタ
PclRegister() {
cloud_in = new PointCloudT;
}
error: no viable overloaded '=' cloud_in = new PointCloudT;
を* PointCloudT :: Ptrは* boost :: shared_ptr *に基づいています。クラスのコンストラクタで明示的に初期化しないと、デフォルトでnullptrに初期化されます。 nullptrを逆参照しようとすると、表示されるエラーが発生します。そのため、使用する前にcloud_ *変数に有効なポインタを割り当てるようにしてください。 –
ありがとうございますが、コンストラクタでどのように初期化しますか?私は 'cloud_ * = new PointCloudT'と' cloud_ *(new PointCloudT) 'を試しましたが、どちらもコンパイルエラーを出します。 – clicky