我需要帮助才能很好地理解struct
我有这段代码:
struct PCD
{
    PointCloud::Ptr cloud;
    std::string f_name;
    PCD() : cloud (new PointCloud) {};
};
但我不明白这一行怎么可能:
PCD() : cloud (new PointCloud) {};
或者更好,它有什么作用?struct中的一个struct?
我在哪里可以找到一个很好的解释?
我需要帮助才能很好地理解struct
我有这段代码:
struct PCD
{
    PointCloud::Ptr cloud;
    std::string f_name;
    PCD() : cloud (new PointCloud) {};
};
但我不明白这一行怎么可能:
PCD() : cloud (new PointCloud) {};
或者更好,它有什么作用?struct中的一个struct?
我在哪里可以找到一个很好的解释?
cloud是指向PointCloud对象的指针。它是PCD结构的成员。当使用初始化器 list初始化此结构时,该指针被分配一个新PointCloud对象。
这很可能在PointCloud结构/类中找到:
typedef PointCloud* Ptr;
    PCD() : cloud (new PointCloud) {};
是一个 PCD 构造函数,它使用新的 PointCloud 实例初始化云变量。
struct PCD
{
    PointCloud::Ptr cloud;
    std::string f_name;
    PCD() : cloud (new PointCloud) {};
};
可以重写和可视化为:
struct PCD
{
public:
    PointCloud::Ptr cloud;
    std::string f_name;
    PCD();
};
PCD::PCD() : cloud (new PointCloud) {};
    结构是一种一切都是公开的类。在这里,您正在查看 struct PCD 的默认构造函数及其数据成员之一的初始化。我们不知道 PointCloud 是结构还是类,但似乎 PCD 包含该类型实例上的指针。所以默认构造函数创建一个新实例。