It's my understanding a union
's size is that of the largest member on that union. Does anyone know how a union behaves when a non-fixed size container such as a string
is added to it? What is the size? Also, how does the size change when the new placement operation is used? Thanks!
Here is an example:
#include <string>
using namespace std;
class X {
public:
union {
int i;
string s;
};
X(string ss) { new(&s) string{ss}; };
~X() { s.~string(); };
};
int main(int argc, char *argv[])
{
X xx{"abc"};
return 0;
}