mardi 4 avril 2017

Initialize base class with data member from derived

Consider a code

struct X {
    X (int n) {...}
};

struct Base {
    Base(X & x) {...}
};

struct Derived : public Base {
    Derived() : Base(x), x(2) {}
    X x;
};

Code works and i see no issue there but i'm concerned about the look of : Base(x), x(2) statement. First pass the instance to Base and after you initialize the actual object. Is this the the only way to express the intention?

Aucun commentaire:

Enregistrer un commentaire