jeudi 30 avril 2015

Enable default initilizer list constructor

I believe modern C++ initializer list are very usefull for initializing structure, sometime to the point of removing the need for defining your own constructor

struct point
{
    float coord[3];
};

point p = {1.f, 2.f, 3.f}; // nice !

However, such a construction doesn't work when my structure inherit from another structure

template<typename T>
class serializable
{
    protected:
        serializable() = default;
    ...
    // other stuff
}

struct point : public serializable<point>
{
    float coord[3];
};
point p = {1.f, 2.f, 3.f}; // Doesn't work :(

I tried adding point() = default; to my point structure, but that didn't work either.

  • Work can I enable sur an initialization for my structure with inheritance ?

Aucun commentaire:

Enregistrer un commentaire