I have a union that looks like this:
union {
int intValue;
double doubleValue;
std::string stringValue;
void *pointerValue;
} values;
When I compile it, I get this error message (yes, I did #include <string>
):
./Value.hh:19:19: error: union member 'stringValue' has a non-trivial copy constructor
std::string stringValue;
^
/Developer/SDKs/MacOSX10.7.sdk//usr/include/c++/4.2.1/bits/basic_string.h:434:7: note: because
type 'std::basic_string<char>' has a user-declared copy constructor
basic_string(const basic_string& __str);
^
I compile it using this command:
$ clang++ *.cc -isysroot /Developer/SDKs/MacOSX10.7.sdk/ -shared
How can I use an std::string
in a union?