one variable to hold different types?

Started by
10 comments, last by Rebooted 18 years ago
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 ;)
_______________The essence of balance is detachment. To embrace a cause, to grow fond or spiteful, is to lose one''s balance after which, no action can be trusted. Our burden is not for the dependent of spirit. - Mayar, Third Keeper
Advertisement
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.

This topic is closed to new replies.

Advertisement