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,045 of 33,346    |
|    Ralf Fassel to All    |
|    Re: sequence of inheritance from virtual    |
|    16 May 13 05:55:22    |
   
   From: ralfixx@gmx.de   
      
   * Richard Damon    
   | The order of inheritance should not matter for conforming code. A   
   | likely issue is code that assumes &Derived == &Base and does invalid   
   | casting on it.   
      
   That's indeed involved. I have two libraries, which need to pass   
   objects of class Base. For some reason I have to pass these via a   
   string representation. I do:   
      
    library 1:   
    Base *ptr = &Derived;   
    ptr->foo(); // ok   
    std::ostrstream ptrstr1 << (void*) ptr; // assume ptrstr1 is a   
   global variable   
      
    library 2:   
    std::istrstream ptrstr2(ptrstr1.str());   
    void *ptr;   
    ptrstr2 >> ptr;   
    Base *bptr = (Base*)ptr;   
    bptr->foo(); // crash if Base is not the first in inheritance list   
   of Derived   
      
   I have checked that the bptr in lib2 has the same value as ptr in   
   lib1. I thought that casting to/from void* using the same class in   
   both directions was ok, but maybe I'm missing something fundamental   
   here...   
      
   R'   
      
      
   --   
    [ 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