Okay, first off: I have been spoiled by Java.
So, now, I am going back to programming in C++ and I am having a slight problem. In Java I made much use of the instanceof operator to determine which derived class an object was an instance of. Now, sure enough, I was coding in C++ the other day and wanted to use that same thing, but... It looks like there is no such thing. So the question is:
Suppose I have some base class, and a bunch of derived classes. I also have a method that should process an object. And that object can be an instance of any of the derived classes. So, I specify the type of the parameter as the base class. However, for bookkeeping purposes, I would still need to know exactly which of the derived classes the parameter is an instance of. Is there any way at all to do it? (Short of putting an identifyier string member into the base class and initializing it to different values in the derived classes?)
Any help would be appreciated.
So, now, I am going back to programming in C++ and I am having a slight problem. In Java I made much use of the instanceof operator to determine which derived class an object was an instance of. Now, sure enough, I was coding in C++ the other day and wanted to use that same thing, but... It looks like there is no such thing. So the question is:
Suppose I have some base class, and a bunch of derived classes. I also have a method that should process an object. And that object can be an instance of any of the derived classes. So, I specify the type of the parameter as the base class. However, for bookkeeping purposes, I would still need to know exactly which of the derived classes the parameter is an instance of. Is there any way at all to do it? (Short of putting an identifyier string member into the base class and initializing it to different values in the derived classes?)
Any help would be appreciated.
Comment