<div><br></div><div><div class="gmail_quote">On 13 June 2011 06:29, David Blaikie <span dir="ltr">&lt;<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font face="arial, sans-serif"><span style="border-collapse:collapse">shared_from_this() throws bad_weak_ptr if it&#39;s called in a derived destructor even if the object is heap allocated, does anyone know if this is intended? And if so, why?</span></font></blockquote>

<div><br></div></div><div>What else could it do? if the dtor is running the refcount has reached zero... and, well, you know, the dtor is running.<br><br>If you created a shared_ptr to that object - what would happen when that new shared_ptr went out of scope? The refcount would reach zero (again) &amp; the object would be double deleted.</div>
</div></blockquote><div><br></div><div>It&#39;s possible to create smart_pointers with null deleters though that in itself doesn&#39;t solve my problem.�</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote">
<div><br></div><div>What semantics were you expecting?�</div></div></blockquote><div><br></div><div>The problem I was facing involved a cyclic data structure (two way references) and was implemented using weak_ptrs. When an object was deleted it was necessary to notify its referers of its deletion which I was looking to do using a weak_ptr.</div>
<div><br></div><div>However, I then realised that although weak_ptrs are great, they are not useful at destruction time due to the fact that there is no smart_pointer remaining with which they are validated, so I have re-implemented using raw-pointers.</div>
<div><br></div><div>It&#39;s hit upon a major semantic difference between smart pointers and raw pointers. I suspect that it may be possible to implement a smart pointer system that could actually continue to correctly mask pointers during deletion (perhaps by deleting the managed object just before the last remaining shared_ptr internals are destroyed).</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org">Boost-users@lists.boost.org</a><br>
<a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br></blockquote></div><br></div>