jeudi 7 septembre 2017

Initialising inherited structure with initialiser list [duplicate]

This question already has an answer here:

I'm trying the following:

struct A
{
    int x;
};

struct B: A
{
    int y;
};

B foo = {1, 2};

But I get:

error: could not convert '{1, 2}' from '<brace-enclosed initializer list>' to 'B'

This is using C++11. Can I get round it without defining an explicit constructor?

Aucun commentaire:

Enregistrer un commentaire