D pointers #2

Thiago Macieira thiago at kde.org
Thu Oct 20 06:27:30 BST 2005


Maks Orlovich wrote:
>It outputs A, B, C. If virtuals didn't work, it would output A, A, A.
>In fact, virtuals very much work inside the constructor --- except that
> when you're in a constructor of a superclass, your class -is- the
> superclass.

Right. But the point is: people expect it to output C, C, C, because it's 
the virtual function "virt" that is called. I remember a certain job 
interview asking exactly that, recently :-)

From the technical point of view, a call to a virtual function from inside 
the constructor or destructor is no different than a call to a 
non-virtual one: it doesn't go through the virtual table.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

5. Swa he géanhwearf tó timbran, and hwonne he cóm, lá! Unix cwæð "Hello, 
World". Ǽfre ǽghwilc wæs glæd and seo woruld wæs fréo.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20051020/d13e0303/attachment.sig>


More information about the kde-core-devel mailing list