Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Cannot predict ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 9 Topic 9371 of 10094
Post > Topic >>

Cannot predict if shared_from_this will throw

by Rodolfo Lima <rodlima@[EMAIL PROTECTED] > Mar 13, 2008 at 02:32 AM

According to
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1450.html,
std::enable_shared_from_this<T>::shared_from_this will throw
std::bad_weak_ptr if the object isn't being referenced by a
shared_ptr. This leads to a problem when one might want to avoid an
exception and doesn't know if it'll occur or not.

Is there any rationale behind this behavior? In other words, why
shared_ptr's ctor that accepts an weak_ptr should throw an exception
if weak_ptr is expired? Why not simply make the shared_ptr empty?

Another solution that doesn't involve changing shared_ptr's ctor
semantics would be adding a member function to enable_shared_from_this
that returned the internal weak_ptr expire status.

Regards,
Rodolfo Lima.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 9 Posts in Topic:
Cannot predict if shared_from_this will throw
Rodolfo Lima <rodlima@  2008-03-13 02:32:45 
Re: Cannot predict if shared_from_this will throw
Carl Barron <cbarron41  2008-03-13 12:00:55 
Re: Cannot predict if shared_from_this will throw
Lance Diduck <lancedid  2008-03-13 13:12:39 
Re: Cannot predict if shared_from_this will throw
Alberto Ganesh Barbati &l  2008-03-16 15:45:07 
Re: Cannot predict if shared_from_this will throw
Carl Barron <cbarron41  2008-03-17 01:51:18 
Re: Cannot predict if shared_from_this will throw
Rodolfo Lima <rodlima@  2008-03-17 01:51:59 
Re: Cannot predict if shared_from_this will throw
"Chris Thomasson&quo  2008-03-18 03:43:06 
Re: Cannot predict if shared_from_this will throw
Alberto Ganesh Barbati &l  2008-03-19 19:59:43 
Re: Cannot predict if shared_from_this will throw
"Chris Thomasson&quo  2008-03-20 18:46:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 15:01:08 CDT 2008.