I think we're really discussing how polymorphism the 'general concept' can be achieved using C++ rather than the just the specific 'polymorphic' language facilities designed into C++.
I came up with this snip code to show the concept of using union with polymorphism. there could be practical application by using union because it saves space.
Ok.. So how do we exploit polymorphism using unions??
The real question is not how, but why. Why exactly would I want to use a union
to implement polymorphism when the language intrinsically supports it with inheritance
and virtual functions.
If asked how to exploit polymorphism using unions during a job interview, the
right answer is to walk out and find a different job. The concept is stupid.
I guess helios has become busy..!! Hope he ll give us the explanation.. maybe he had someother idea in his mind when he cited unions as a tool for polymorphism...
@everid
Thanks for your idea. But again here we use virtual functions as the tool of polymorphism and we use unions for efficiency..