[C++-sig] why does the "shared_ptr<X> const&" silently become 0xCCCCCCCC
ZaeX
zaexage at gmail.com
Wed Mar 11 07:05:18 CET 2009
Hi, All:
I used a "shared_ptr<A> const&" to store a ref of A in B;
Well, the constructor of B seems ok, the share_ptr<A> seems to be well
initialized;
but after the constructor, I found the the pointer silently become
0xCCCCCCCC
///////////////////////////////////// below are the simplified class
definitions
class A{};
class B
{
private:
shared_ptr<A> const& m_ptr;
public:
B(shared_ptr<A> const& ptr):m_ptr(ptr) {cout<<m_ptr.get()<<endl;}
void ShowPtr(cout<<m_ptr.get()<<endl;)
}
/////////////////////////////////// below are my exporting code
class_<B, auto_ptr<B> >("B", init<shared_ptr<A> const&>())
.def("ShowPtr", &B::ShowPtr)
;
class_<A, shared_ptr<A>, noncopyable >("A")
;
/////////////////////////////////// below are python code
a = A()
b = B(a) #cout output the ptr of a
b.ShowPtr() #cout output 0xCCCCCCCC
============================================
I'm quite confused by the behaviors here. Could you tell me what goes wrong?
--
Time is mana, we must hurry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090311/0bc59282/attachment.htm>
More information about the Cplusplus-sig
mailing list