Can I safely use members to initialize others?
class Class {
public:
Class(X argument) : memberA(argument), memberB(memberA) {}
A memberA;
B memberB;
};
Here we use the argument to the constructor to initialize memberA
. We then rely on the fact that this happens before the initialization of memberB
and initialize memberB
using memberA
.
If we assume X
, A
, and B
to be std::string
the above example works (tested with gcc
), as long as we do not change the order in which the members are declared. But is this actually guaranteed by the standard or am I abusing an implementation detail of the compiler?