inherited classes w/ different functions under the same name
Hello all,
I have two different classes that are both inherited from the same parent class.
class BaseClass {...};
class childClass_1: public BaseClass {...};
class childClass_2: public Baseclass {...};
I have a vector that stores pointers to objects of the type BaseClass:
std::vector <BaseClass *> baseObjects;
now i want to be able to do something like this:
int i;
for (i=0;i<baseObjects.length();i++) {
baseObjects.at(i)->doSomething ();
}
however, the contents of the function doSomething is different for childClass_1 and childClass_2. how can i arrange this? some sort of function template in BaseClass?
Thanks in advance! I really appreciate it -
- iochi
Re: inherited classes w/ different functions under the same name
I got it - virtual members.
http://www.cplusplus.com/doc/tutorial/polymorphism/
good luck to anyone reading this -
Re: inherited classes w/ different functions under the same name