Consider a hypothetical scenario in which two classes can be built by default or built from each other, but in any case considered expensive (a deliberately contrived example follows):
struct PrivateKey;
struct PublicKey {
PublicKey();
PublicKey(const PrivateKey& b);
...members...
};
struct PrivateKey {
PrivateKey();
PrivateKey(const PublicKey& a);
...members...
};
(Of course, this could be reduced to one class, but the justice of the issue has not been touched. Say, for the sake of coherence, there is no symmetry between one and the other.)
Now there is a structure that contains instances of both and needs this cross-initialization. However, we may need both directions, so the initializer lists cannot cut it (they are not executed in the specified order, but in the order in which the members are defined, and the order cannot be fixed here):
struct X {
PublicKey a;
PrivateKey b;
X(int): a(), b(a) { }
X(float): b(), a(b) { }
};
Of course I could try:
struct X {
PublicKey a;
PrivateKey b;
X(int): a(), b(a) { }
X(float): a(), b() { a = PublicKey(b); }
};
, PublicKey X , , . PublicKey::PublicKey(). , , X, - , , , X::X(float). ?