2009/6/12 Tiago Alves
<talves@tapestry.pt>
Hi, and sorry for the probable newbieness of this question!
I want to put weak_ptr into a piece of memory previously allocated.
this is my code:
// construct a weak_ptr from a share_ptr
boost::weak_ptr<Obj>* cameraPtr = new boost::weak_ptr<Obj>(obj_share_ptr);
// lua_newuserdata allocs memory and returns a pointer to it, just like malloc.
boost::weak_ptr<Obj>* camera = static_cast<boost::weak_ptr<Obj>*>(lua_newuserdata(pLuaState,sizeof(boost::weak_ptr<Obj>)));
Now i want camera to be a weak_ptr of ObjPtr.
I tried different ways to do this, such as
*camera = boost::weak_ptr<Obj>(obj_share_ptr);
or
camera->swap(*cameraPtr);
or
*camera = *cameraPtr;
Try this:
new (camera) boost::weak_ptr<Obj>(*cameraPtr);
Roman Perepelitsa.