|
-
December 22nd, 2011, 11:14 PM
#1
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
-
December 23rd, 2011, 01:07 AM
#2
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 -
-
December 23rd, 2011, 06:31 AM
#3
Re: inherited classes w/ different functions under the same name
yep, that's the one
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|