2016-05-19 26 views
0

これは動作します:クラスインスタンスをクラスメンバに移動した後、クラスインスタンスを初期化できませんか?

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2 (new pcl::PointCloud<pcl::PointXYZ>); 

しかし、これは動作しません。

Class.h、プライベート変数

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud; 

Class.cpp、コンストラクタ

cloud (new pcl::PointCloud<pcl::PointXYZ>); 

メイクに失敗した:

error: no match for call to ‘(pcl::PointCloud<pcl::PointXYZ>::Ptr {aka boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >}) (pcl::PointCloud<pcl::PointXYZ>*)’ 
    cloud (new pcl::PointCloud<pcl::PointXYZ>); 

どうして同じではないのですか? .cppから見た唯一の違いは、型が左側(宣言中)であり、一方がすでに.hで宣言されていることですが、エラーはどちらも同じ引数を使用するにもかかわらず、引数について文句を言うようです。

+1

私は質問に答えるには十分だとは思っていませんが、初期化子のliで 'cloud'を初期化していないようですst。質問を編集してコンストラクタ全体を表示する必要があります。 – dwcanillas

+1

'bar(foo)'は代入構文ではありません。 [mcve]を表示してください。 –

答えて

2

私はあなたがいないメンバー初期化子リストでコンストラクタ本体でそれを初期化していることを考える:

struct A{ 

    A(int){} 

    A(){} 
}; 

struct B 
{ 
    A a; 

    B(): a(52) //correct syntax 
    { 
     a(52); //error: no match for call to... 
    } 
}; 



int main() 
{  
    A a(5); //ok this works 
} 

あなたのClassメンバー初期化子リストで cloud (new pcl::PointCloud<pcl::PointXYZ>);

を配置する必要があります。

Class(): cloud (new pcl::PointCloud<pcl::PointXYZ>) 
{ 
//constructor body 
} 
+0

前に "イニシャライザーリスト"について知りませんでした! (C#、Javascriptから)ありがとう! – 5argon

関連する問題