Short answer
In C, joining is just a matter of how to interpret data stored in a specific place. Data is passive.
++ . , . () (, , ), , . : , .
:
union U {
string s;
int i;
U (string s) : s(s) { cout << "s is active"<<endl;}
U (int i) : i(i) { cout << "i is active"<<endl;}
U() : s() { cout << "s is active by default" <<endl; }
~U() { cout << "delete... but what ?"<<endl; }
};
, :
U u("hello");
s
. memeber :
u.s += ", world";
cout << u.s <<endl;
, , ( ++). , , :
u.i=0; // ouch!!! this is not the active member : what happens to the string ?
undefined ( s , ). . , i, :
u.s="goodbye"; // thinks that s is an active valid string which is no longer the case
, , s . s , undefined.
,
?
:
M N (, ), u m n, :
u.m.~M();
new (&u.n) N;
, :
u.s.~string();
u.i=0;
new (&u.s) string("goodbye");
cout << u.s <<endl;
, ()