dimanche 21 juin 2020

Brace initialization with constructor for class with virtual function

I understand aggregates cannot have virtual member functions, yet this code compiles

struct B {
    B(int yIn) :y(yIn) {}
    int y;
    virtual void f() {}
};

B b = {3}; 

Is brace initialization different than aggregate initialization, or is this class a valid aggregate because of its constructor?

Aucun commentaire:

Enregistrer un commentaire