I just built the boost.python 1.36 with Python2.6.1 and tried again, and it still turned out to be 0xcccccccc in debug build.<br>And I made sure this is not caused by 'a = B(a)'-like typo.<br><br>Maybe it's something concerning the project setting or something went wrong with my compiler(?)<br>
Whatever, I think taking a workaround would be a better choice, and maybe I will figure out what really went wrong sometime later..<br><br><div class="gmail_quote">On Thu, Mar 12, 2009 at 8:36 PM, athor <span dir="ltr"><<a href="mailto:thorena@gmail.com">thorena@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im"><br>
<br>
zaexage wrote:<br>
><br>
> I got a 'class Manager' which contains a std::set of shared_ptr<Entity>;<br>
> and 'class Entity' has a auto_ptr<StateMachine> as member<br>
> and 'class StateMachine' needs shared_ptr<Entity> as member variable to<br>
> access some functions outside.<br>
><br>
> So, in order to break cyclic reference, I make the StateMachine to own a<br>
> 'shared_ptr<Entity> const&', I think it's kind of reasonable.<br>
><br>
<br>
</div>I also use VS2008 with Python 2.5 and the boost libraries using the boost<br>
consulting installer so it seems identical (which is strange).<br>
<br>
I'd guess there's a simple typo somewhere. By using a const& to the<br>
shared_ptr, it may be deallocated once the program (Python/C++) thinks the<br>
original shared_ptr is not in use anymore. For example,<br>
a = A()<br>
a = B(a)<br>
would be such a simple typo. A would immediately be deallocated but the<br>
const ref in B wouldn't know.<br>
<br>
A few comments:<br>
<br>
* I assume each entity owns a unique StateMachine. Otherwise, the<br>
auto_ptr<StateMachine> may be a problem. I've had many strange bugs from<br>
using auto_ptr and thus I only use shared_ptr nowadays.<br>
<br>
* You don't *need* a const& to break cyclic reference. Passing a shared_ptr<br>
by value works too.<br>
Example:<br>
-------------------------------<br>
// Forward Declare Entity<br>
class Entity;<br>
<br>
// Declare StateMachine<br>
class StateMachine<br>
{<br>
StateMachine(shared_ptr<Entity> e) {...}<br>
};<br>
<br>
// Declare Entitity<br>
class Entity<br>
{<br>
Entity(shared_ptr<StateMachine> s) {...}<br>
};<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://www.nabble.com/why-does-the-%22shared_ptr%3CX%3E-const-%22-silently-become-0xCCCCCCCC-tp22449314p22475430.html" target="_blank">http://www.nabble.com/why-does-the-%22shared_ptr%3CX%3E-const-%22-silently-become-0xCCCCCCCC-tp22449314p22475430.html</a><br>
</font><div><div></div><div class="h5">Sent from the Python - c++-sig mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
Cplusplus-sig mailing list<br>
<a href="mailto:Cplusplus-sig@python.org">Cplusplus-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/cplusplus-sig" target="_blank">http://mail.python.org/mailman/listinfo/cplusplus-sig</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Time is mana, we must hurry<br>