Suppose a class D
maintaining a vector of objects of class C
, and suppose that the first three elements of the vector shall be accessible through data members field0 .. field2
, which are references to objects of class C
.
If we initialise data members field0 .. field2
at the point of their declaration, and none of the constructors of D
uses explicit mem-initializer lists, is it guaranteed that the data members will always be initialised with a correct reference to the objects held in the vector (if we consider subclassing, copying, moving, ... an object of class D
)?
Note that the question is not about the order of initialization but more on "can anything in the use of class D (including subclassing) prevent the data members from being initialised"?
class C{
};
class D{
protected:
std::vector<C> myC = std::vector<C>(3);
public:
C &field0 = myC[0];
C &field1 = myC[1];
C &field2 = myC[2];
D () {}; // no mem-initializers
};