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

List:       kde-core-devel
Subject:    BIC and virtual methods
From:       Lubos Lunak <l.lunak () sh ! cvut ! cz>
Date:       2002-02-14 15:41:52
[Download RAW message or body]


 Hello,

 before I forget and it's too late: As we all know and as the BC page 
http://developer.kde.org/documentation/kde2arch/devel-binarycompatibility.html 
says, one cannot add new virtual methods without breaking binary 
compatibility. I'd like to propose a change that would make it possible to 
add new virtual methods (or change existing non-virtual ones to virtual). 
It's even uglier than the private d-pointer data, but I think people 
desperately needing it won't mind that much :).

 See the attached example. Old.cpp/old.h is the original implementation of 
class A and B, new.cpp/new.h is a new one, binary compatible with it, with a 
new "virtual" method 'added()' and 'changed()' changed from non-virtual to 
virtual. Please use your favourite diff tool to see the changes.

 There are also two files old_use.cpp and new_use.cpp, which use the library 
containing the classes A and B. Old_use.cpp uses only the methods available 
in the old version, new_use.cpp uses also the new methods, and old_use.cpp of 
course also works with the new implementation (and note that changed() now 
behaves like virtual).

 The trick is adding one virtual method to every class :
  virtual void virtual_hook( int, void* );
 And this methods works as a dispatcher for the calls. The implementation of 
the new "virtual" methods is added as a non-virtual method XYZ_impl(). The 
method itself only packs all its arguments in a struct, passes it via the 
void*, and calls virtual_hook(). This virtual method then based on the id 
call the correct _impl() method. I hope the example explains the details.

 Comments? 

-- 
 Lubos Lunak
 llunak@suse.cz ; l.lunak@kde.org
 http://dforce.sh.cvut.cz/~seli

["bci_virt.tar.bz2" (application/x-bzip2)]

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

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