A more general solution to your problem is to use a type that can hold different types at run-time, like VCL's Variant type (inherited from Object Pascal).
A quick search revealed boost::any - it might be just what you're looking for ;)
one variable to hold different types?
A discriminated union class is usually a better solution than a raw C union, assuming you are using C++ and not C.
I'd suggest using boost::variant.
There is also boost::any, but you can't restrict the types it takes - it can hold anything.
I'd suggest using boost::variant.
There is also boost::any, but you can't restrict the types it takes - it can hold anything.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement