<div class="gmail_quote">2009/6/12 Tiago Alves <span dir="ltr">&lt;<a href="mailto:talves@tapestry.pt">talves@tapestry.pt</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi, and sorry for the probable newbieness of this question!<br>
<br>
I want to put weak_ptr into a piece of memory previously allocated.<br>
<br>
this is my code:<br>
<br>
// construct a weak_ptr from a share_ptr<br>
boost::weak_ptr&lt;Obj&gt;* cameraPtr = new boost::weak_ptr&lt;Obj&gt;(obj_share_ptr);<br>
// lua_newuserdata allocs memory and returns a pointer to it, just like malloc.<br>
boost::weak_ptr&lt;Obj&gt;* camera = static_cast&lt;boost::weak_ptr&lt;Obj&gt;*&gt;(lua_newuserdata(pLuaState,sizeof(boost::weak_ptr&lt;Obj&gt;)));<br>
<br>
Now i want camera to be a weak_ptr of ObjPtr.<br>
I tried different ways to do this, such as<br>
*camera = boost::weak_ptr&lt;Obj&gt;(obj_share_ptr);<br>
or<br>
camera-&gt;swap(*cameraPtr);<br>
or<br>
*camera = *cameraPtr;<br>
</blockquote></div><br>Try this:<br>new (camera) boost::weak_ptr&lt;Obj&gt;(*cameraPtr);<br><br>Roman Perepelitsa.<br>