|
-
January 5th, 2010, 05:03 AM
#1
Foo having a boost::weak_ptr<Foo> member
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;
}
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
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).
Cheers.
-
January 5th, 2010, 08:41 AM
#2
Re: Foo having a boost::weak_ptr<Foo> member
I'd say you have to include <boost/weak_ptr.hpp> as well. It seems as if your compiler does not recognize that class due to the missing include.
-
January 5th, 2010, 05:45 PM
#3
Re: Foo having a boost::weak_ptr<Foo> member
 Originally Posted by Richard.J
I'd say you have to include <boost/weak_ptr.hpp> as well. It seems as if your compiler does not recognize that class due to the missing include.
That completely slipped my mind haha. Cheers.
-
January 6th, 2010, 09:47 AM
#4
Re: Foo having a boost::weak_ptr<Foo> member
I could not believe that you miss that solution.
Thanks for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|