As described in the code below: it doesn't seem possible, but I could really use it... Does anyone have any ideas of how to get around this?
Code:#include <iostream> #include "boost/shared_ptr.hpp" class GUI_Object; typedef boost::shared_ptr<GUI_Object> gui_object_ptr; typedef boost::weak_ptr<GUI_Object> weak_gui_object_ptr; class GUI_Object { public: GUI_Object() {} void Set_Parent(weak_gui_object_ptr p) { parent = p; } protected: weak_gui_object_ptr parent; }; int main() { GUI_Object g; return 0; }The reason that I am trying to do this is because I only recently added the "parent" member to my GUI_Object class. I was creating GUI_Object-derived objects on the stack, and so the pointers that other objects were holding to these objects (as their "parent") were being invalidated eventually. I thought that this could solve my issue (just means that I have to create a shared_ptr wrapper of each GUI_Object-derived object that will be a parent).Code:Error 1 error C2079: 'GUI_Object::parent' uses undefined class 'boost::weak_ptr<T>' e:\dev\projects\test\test\main.cpp 20 Error 2 error C2440: '=' : cannot convert from 'weak_gui_object_ptr' to 'int' e:\dev\projects\test\test\main.cpp 17
Cheers.




Reply With Quote