I'm trying to implement a GenericVariable (which should allow people to just use that type to do practically anything) by using Unions. I want people to use: bool, long int, long double and std::string.
The errors I get with my current compiler (which, at that, is pretty old) are:
member 'std::string GenericVar::GenericVal::st' with constructor not allowed in union
member 'std::string GenericVar::GenericVal::st' with destructor not allowed in union
member 'std::string GenericVar::GenericVal::st' with copy assignment operator not allowed in union
Using pointers is an alternative, but I really need to "embed" them in some way, not just refer to them.
You're constructing something akin to Microsoft's VARIANT type. The union holds the built in types and pointers to more complicated bytes. An enclosing struct has a tag, that tracks what type the union is at the moment. You can put a constructor on this enclosing struct/class. But the union pretty much the same primitive device as it is in C.
Hm, both look promising and the variant is indeed more like a union.. but any provides the full functionality I've been looking for, so I think I'll go with that.
The reason I need this functionality is because of the programming language I'm working on, I want it to be very easy to use.