3 Mar
2006
3 Mar
'06
12:39 a.m.
adharankar@verizon.net wrote:
class A { public: int val; }; typedef boost::shared_ptr<A> APtr;
struct S { public: APtr aptr; };
struct S *func(void) { A *a = new A; a->val = 12;
APtr aptr(a);
struct S *s = (struct S *)malloc(sizeof(struct S));
s->aptr is uninitialized here because you haven't invoked the constructor of S yet. s now points to raw bytes, not to an object of type S. Use new( s ) S; to construct an object in this storage, or better yet, just use S * s = new S;
s->aptr = aptr; return s; }