No, I don't think inheritance works for enum types.
You can of course cast the enums to int, but that requires you to know which element has which type to cast them back correctly.
This doesn't seem to make much sense anyway.
You should explain what you're trying to do and we can recommend you a more adequate solution.
means are we able to use ENUM data type to make a stack of different data types...
As for the answer of first post (ARE we able to make stack of variables having different data types???) some one told me " make a stack of type enum" and i m confused about it
If that's really what that person said, disregard it. It's nonsense.
You could store pairs of an enum type that specifies the type of the second member of the pair (which would be of type void*). That's a bad idea though, so it's better to forget about it right away.
Make a base class that has an interface which is common to all subclasses and make a stack of that base class.
If you ever need to upcast, you can do it with dynamic_cast.
ARE we able to make stack of variables having different data types???
I believe the answer is no. Even if you use a class to hold a vector which holds different primitive types the pointer type and vector type will be that of the class name which is a programmer defined type.
How about a stack of Boost.Variant1 or writing a container adapter for Boost.Any2?
Still, let's no forget the [lack of] usefulness of having a heterogeneous container. There's only so much you can do when you don't know the type. If you're going to design an interface that applies to all of the differently-typed elements, you're right back to a container of base class pointers.
Other possibly interesting topics may include the Composite and Null Object patterns. Also, recall the article discussion on type erasure3 (very interesting stuff).
The union approach doesn't quite work because on retrieval, the programmer won't know, for each element,
what type the value is. You need a discriminator, which means a struct:
1 2 3 4 5 6 7
struct part {
int which; // 0 == int, 1 == double, etc
union {
int i;
double d;
} u;
};
But unions in C++ have limited use until C++0x allows the "unionized" types to have user-defined constructors.