Make class-method act diferently depending on which subclass it got called from?(C++)

Started by
4 comments, last by Fruny 17 years, 10 months ago
well, the subject pretty much says it all.. i have a base-class, with 5 other classes derived from it. the base-class has a method which all of the sub-classes inherit. now when i call that method from one of the sub-classes, i want it to act differently depending on which sub-class it got called from. is there some fancy way of knowing which sub-class it got called from or will i have to specify that in a parameter when calling the method? thanks in advance
____________________________________________You don't need a reason to help people. -Zidane/FF9
Advertisement
Use a virtual function, which the classes which inhert override.
read this:

http://www.cplusplus.com/doc/tutorial/polymorphism.html

-me
thanks guys. that helps =)
heh, incredibly quick replies at this place..
____________________________________________You don't need a reason to help people. -Zidane/FF9
I like this reference, personally. :/ (You should probably read the whole page actually.)
Quote:Original post by Zahlman
You should probably read the whole page actually.


People should probably read the whole site, actually.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement