将类实例移动到类成员后,无法初始化它
Cannot initialize a class instance, after I move it to a class member?
这很有效:
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>);
Make失败,原因为:
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中声明了,但尽管我在这两种方式中使用了完全相同的参数,但错误似乎都是关于参数的。
我认为您是在构造函数主体中初始化它,而不是在成员初始化器列表中:
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
}
你必须放置cloud (new pcl::PointCloud<pcl::PointXYZ>);
在您的Class
成员初始值设定项列表中:
Class(): cloud (new pcl::PointCloud<pcl::PointXYZ>)
{
//constructor body
}
相关文章:
- 为什么在C++中首先初始化成员类
- 是否可以防止省略聚合初始化成员?
- 正在复制具有未初始化成员的结构
- 使用大括号或括号初始化成员变量
- C++结构:强制初始化成员?
- C++中未初始化成员布尔变量的默认值是多少?
- 使用默认值初始化成员引用
- 在构造函数中初始化成员时,是否应该在成员上使用 std::move?
- C++使用 { } 初始化成员变量
- 如何根据构造函数参数使用超类类型初始化成员变量?
- OpenGL C++:VBO 的结构包装器不会初始化成员
- 有没有办法在Brace中初始化成员
- 从现有 istream 或类本身创建的 istream 初始化成员 istream
- 从其后声明的另一个成员数据初始化成员数据是否为未定义行为
- 通常应用方法,使用带有构造函数委托的 SFINAE 通过类模板的构造函数初始化成员
- 如何在嵌套类中初始化成员?C
- 是否可以在构造函数主体中初始化成员变量,而不是初始值设定项列表
- 编译器错误,因为构造函数必须显式初始化成员
- 如何使用成员函数初始化成员函数指针
- C 如何使用隐藏的默认构造函数初始化成员