<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Consolas'; font-size:11pt; font-weight:400; font-style:normal;">On Monday 14 July 2008, Rafael Fernández López wrote:<br>
> Hi there,<br>
><br>
> In general, if we used the virtual_hook approach we would be having tons of<br>
> benefits from my very point of view. Why ? All classes with virtual methods<br>
> (at least, those which are very possible to grow when we need to assure<br>
> binary compatibility) would count with a virtual hook and an enum. Is just<br>
> a matter of checking the enum (that could be even called the same on all<br>
> classes) when changing between BIG versions of KDE and see what we need to<br>
> make virtual.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Well, we *do* use virtual_hook:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>kde-svn@midna ~/kde4/kdelibs $ find . -name '*.h' -print0 | xargs -0 grep -l 'void virtual_hook' | wc -l<br>
47<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>I'm pretty sure it was even more extensively used in KDE 3.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Really the type of implementation is not really that big a deal though, the important thing is that it is possible.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>If you already have virtual methods in your class adding virtual_hook() for future expandability does not hurt as you already have a vtable. But if you forgot or chose not to then you can use signals/slots (or the d pointer) depending on whether you've derived from QObject or not.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>At the end of the day though it's really just an implementation detail. Maybe if there were numbers showing that one method should be preferred because it's one-two orders of magnitude faster (on code where the function call actually adds overhead too :P) we could say to prefer a method but we're not at that point yet.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Regards,<br>
- Michael Pyne</p></body></html>