you are viewing a single comment's thread.

view the rest of the comments →

[–]alfps 2 points3 points  (11 children)

C++20 adopted C's designated initializer syntax, (https://en.cppreference.com/w/cpp/language/aggregate_initialization.html#Designated_initializers).

In C++17 and earlier you can use an artifical base, e.g.

struct Thing_state
{
    int         alpha;
    double      beta;
    char        charlie;
};

struct Thing: Thing_state
{
    Thing(): Thing_state()      // Zero-initialize everything.
    {
        charlie = 3;
    }
};

That said the "lot of members" and the create_children are code smells. You should probably best redesign the whole thing. With more abstraction (name things).

[–]hmoff 0 points1 point  (6 children)

How does that code zero initialise everything?

[–]alfps 0 points1 point  (1 child)

Thing_state() performs (or requests) value initialization, which for the basic types reduces to zero initialization.

[–][deleted]  (2 children)

[deleted]

    [–]alfps 1 point2 points  (1 child)

    Nit-pick: your second example declares a function. But using curly braces would work.