Struct in structure in C ++

I need help to understand usage well struct

I have this piece of code:

struct PCD
{
    PointCloud::Ptr cloud;
    std::string f_name;
    PCD() : cloud (new PointCloud) {};
};

But I do not understand how this line is possible:

PCD() : cloud (new PointCloud) {};

or better, what is he doing? A structin struct?

Where can I find a good explanation?

+4
source share
4 answers

cloudis a pointer to an object PointCloud. He is a member of the structure PCD. When this structure is initialized using a list of initializers, a new object is assigned to this pointer PointCloud.

This is probably found in PointCloudstruct / class:

typedef PointCloud* Ptr;
+5
source
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) {};
+3

Struct - , . struct PCD . , PointCloud , , PCD . .

+2
PCD() : cloud (new PointCloud) {};

PCD.

: , . cloud , PointCloud.

Member initializer lists are used to initialize non-static data elements before the constructor body is executed. It is also the only way to initialize members of a reference type.

Read more about constructors and member initialization lists here .

+2
source

All Articles