I have a 20 year old, 100,000 line C program that I am trying to slowly convert to C++. Part of the code has a virtual base class with a large number of derived classes.
Question 1: For each derived class, I want to have a function that takes a pointer to the base class and returns a boolean indicating if the pointer dereferences to that derived class. Right now I use a virtual function for every single derived class, which means that every time I add a new derived class, I have to edit every other derived class include file and put in a funtion that returns false. This can't be the right way to do this!
Question 2: Say I have a function that takes a pointer particular derived class (bob) as an argument, or is a member function of class bob. Is there an elegant way to call this function on a pointer to the base class, assuming I have already checked that the pointer is really from the correct derived class? Right now I do a cast:
This is pretty ugly. There must be a better way!Code:function( (bob*) pointer ) ; ( (bob*) pointer )->function() ;
Thanks for any tips,