F
Fred Zwarts
Consider the following two classes for a given type T_t:
class Base {
private:
T_t *const PointerToT;
public:
Base (T_t &T) : PointerToT (&T) {}
};
class Derived : public Base {
private:
T_t T;
public:
Derived () : Base (T) {}
}
Note that the member T of class Derived is passed to the constructor of its base class.
However, the constructor of class Base uses only the address of T.
Is this defined according to the C++ standard?
Is the layout of the the derived class defined when the constructor of the base class is called,
although the members of the derived class are not yet initialized?
Or does the C++ standard allow that the layout of the members of the derived class is delayed
till after the construction of the base class?
F.Z.
class Base {
private:
T_t *const PointerToT;
public:
Base (T_t &T) : PointerToT (&T) {}
};
class Derived : public Base {
private:
T_t T;
public:
Derived () : Base (T) {}
}
Note that the member T of class Derived is passed to the constructor of its base class.
However, the constructor of class Base uses only the address of T.
Is this defined according to the C++ standard?
Is the layout of the the derived class defined when the constructor of the base class is called,
although the members of the derived class are not yet initialized?
Or does the C++ standard allow that the layout of the members of the derived class is delayed
till after the construction of the base class?
F.Z.