Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,063 of 33,346    |
|    Wil Evers to Francis Glassborow    |
|    Re: [Solved] sequence of inheritance fro    |
|    19 May 13 16:39:57    |
   
   From: bouncer@dev.null   
      
   Francis Glassborow wrote:   
      
   > On 19/05/2013 08:04, Stuart wrote:   
   >   
   >> Well, I learned something too. I didn't know that the compiler is   
   >> allowed to lay out the base class members in a different order than   
   >> the one that is given in the class definition. So if one has to   
   >> achieve some memory layout, one has to take special care if one of   
   >> the base classes contains virtual methods.   
      
   > Well a class that includes at least one virtual function is likely   
   > to be more vulnerable, but, IIUC, the implementation is at liberty   
   > to lay out a derived class' base classes anyway it likes. There are,   
   > IIRC, some limitations on the relationship between a pointer to the   
   > derived class and a pointer to the first base class in the   
   > declaration of the derived class.   
      
   Are you sure? As far as I know, if we have...   
      
   class Base { /* ... */ };   
   class Derived : public Base { /* ... */ };   
      
   ...then for a Derived object, the compiler is free to either use a   
   layout in which the Base part comes first, or one in which the Derived   
   part comes first (which would not be very practical, but that's beside   
   the point).   
      
   I think the lesson to learn from this thread is that a void pointer   
   obtained from the address of an X must not be cast back to a pointer   
   to some other type, even if that other type is closely related to X.   
      
   Regards,   
      
   - Wil   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca