Mail Archives: djgpp/1998/05/03/17:35:00
>In my bstClass I have the public search function declared as
>virtual.
It doesn't matter. The behavior that is to be overriden is
method SearchTree() and not Search(). Search() does always the
same, ok?
>I want to override the protected recursive function that it
>calls.
Yes, you know what you want.
virtual stands for "this method can have a different bahavior in
a derived class" and no "this method can call another method
that can have a different bahavior in a derived class".
>Do I declare the protected function as virtual and is that
>allowed?
Yes, it is. Overriding has nothing to do with access control
(public, protected, private). SearchTree() could be private!
Nathan, I will tell you the whole history. If you take a look at
the generated assembly code you will se the difference is at the
method call. The compiler sees a method call and thinks "Is the
called method virtual?". If it is the case the compiler
generates a indirect call, a smart one. This call, at execution
time, gets the address of the proper method from a table that is
connected with the real class of the called object.
This issue is actually confusing sometimes. I hope this
explanation improves your understanding of what is "virtual".
[]s
- Raw text -