I’d like to define a union, for reading special kind of binary files. The union should have two members one of int and the other a kind of string, or any other that’s the question; what is the best way to do this?
union uu {
int intval;
wstring strval;
uu(){ memset(this, 0, sizeof(this)); }
}
it says: “Member strval of union has copy constructor”
I think strval should have a * or a &;
how would you define it?
thanks in advance
Oops
You can’t do it. Members of unions must be POD types – i.e. they must not have constructors or destructors. And even if you could, your call to memset would trample all over the string, leading to undefined behaviour. You can of course use a pointer: