PDA

View Full Version : Simple question about heritances



SkripT
17th March 2006, 17:50
Hi all, I have a class with functions A and B. Function A calls to B. Well, I need to subclass this class because I need to reimplement the function B (the function A remains the same). The question is: in the new class, when A calls to B wich "version" of B is called: the "new" or the "old" one. If the answer is the version from the parent class (as I think) what's the best solution to make that the function A calls to the new B in the subcalassed class? Defining B as virtual in the parent class and reimplement it in every subclass, maybe?

Thanks.

jacek
17th March 2006, 17:58
Defining B as virtual in the parent class and reimplement it in every subclass, maybe?
Yes, but you don't have to reimplement it everywhere.

SkripT
17th March 2006, 18:10
Yes, but you don't have to reimplement it everywhere.

Do you mean jacek that If I define B in the main class as virtual but I also implement it, it will work as I need?

fullmetalcoder
17th March 2006, 18:30
in both classes declares B as virtual and reimplement it then everything will work fine : that's the point of dynamic function linking.

SkripT
17th March 2006, 18:33
Thanks both!