[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Virtual functions and binary compatibility
From:       Rolf Magnus <ramagnus () t-online ! de>
Date:       2002-07-09 21:46:15
[Download RAW message or body]

On Tuesday 09 July 2002 15:38, Trevor Harmon wrote:

> On a related note, could someone please refer me to a good explanation of
> virtual functions, specifically when and when not to use them? I understood
> it a few years ago but I've been doing Java since, not C++, and I've mostly
> forgotten. Thanks,

virtual functions are needed for polymorphic behavior. If you want to call 
methods of a class through a pointer or reference to its base class and want 
the right method to be called, they have to be declared virtual in the base 
class.
Compilers typically (is there another way?) implement this by adding for every 
class with virtual functions an internal hidden array of pointers with one 
pointer to every virtual function. This array is called the vtable. The 
object then has a pointer to its class's vtable. The compiler will use that 
pointer together with an index into the vtable to call the actual method.
Adding, removing or changing the order of virtual functions in a class changes 
the layout of the vtable of that class, which is why those changes are binary 
incompatible.


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic