How do I change the class of an object to a subclass of its current class in C++?
- by Jared P
I have an array of pointers to a base class, so that I can make those pointers point to (different) subclasses of the base class, but still interact with them. (really only a couple of methods which I made virtual and overloaded) I'm wondering if I can avoid using the pointers, and instead just make an array of the base class, but have some way to set the class to the subclass of my choosing. I know there must be something there specifying the class, as it needs to use that to look up the function pointer for virtual methods. By the way, the subclasses all have the same ivars and layout.
Note: the design is actually based on using a template argument instead of a variable, due to performance increases, so really the abstract base class is just the interface for the subclasses, which are all the same except for their compiled code.
Thanks