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 31,453 of 33,346    |
|    Ulrich Eckhardt to Iker Jamardo Zugaza    |
|    Re: Smart pointers and exceptions    |
|    06 Sep 11 12:30:28    |
      c46ecbd2       From: ulrich.eckhardt@dominolaser.com              Iker Jamardo Zugaza wrote:       >> SPFooInherited pfi;       >> SPFoo& pf = pfi;       >>       >> This of course doesn't compile, because the two are not related.       >       > This code compiles perfectly. While creating the new pf reference, the       > smart pointer to Foo is able to check that the conversion from       > FooInherited is completely valid:       >       > FooInherited* fi;       > Foo* pf = fi;       >       > This is what is done internally in the shared_ptr class (more or less       > with some reference counter handling and such ;)).              You have missed an ampersand! The equivalent using raw pointers is not what       you write here but this:               FooInherited* fi;        Foo*& pf = fi;                     The reason this doesn't compile, just in case it isn't clear, is that you       could now make 'pf' point to a 'Foo', which would in turn make 'fi' point to       a 'Foo', too, even though it promises to point to a 'FooInherited'.                     Uli              --       Domino Laser GmbH       Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932                      [ 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