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,452 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Smart pointers and exceptions    |
|    05 Sep 11 23:47:02    |
      c46ecbd2       From: daniel.kruegler@googlemail.com              Am 06.09.2011 00:19, schrieb Iker Jamardo Zugaza:       > I understand that the runtime cannot solve the       > problem but, Ulrich, sorry       >       >> SPFooInherited pfi;       >> SPFoo& pf = pfi;       >>       >> This of course doesn't compile, because the two are not related.       >       > This code compiles perfectly.              This is probably a compiler defect or some "extension mode" (Do you use       a Visual Studio compiler?). It seems that the compiler allows binding a       temporary to a reference to non-const, which is illegal in standard C++.              > 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 ;)).              This is a different story: The shared_ptr implementations typically       provide a constructor template that accepts pointers of derived types.       But the invocation of such a constructor is a conversion and in the       example code discussed this would have the effect to create a temporary       and bind it to an lvalue-reference to non-const, which is non-conforming.              > My assumption here is then that the runtime uses a different approach       > for calling functions and for catching exceptions even though it could       > look like the same at first sight.              Smart pointer constructions are different from real inheritance       relations. The exception machinery depends on real inheritance relations.              HTH & Greetings from Bremen,              Daniel Krügler                     --        [ 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