Is there a boost or STL class that can wrap a member pointer if it was an member variable?
I have two classes with a circular dependency problem:
- A has a member variable of class B
- B is a subclass of
vector<A>
I originally solved this like this:
A.h:
#include "B.h"
class A
{
B b;
}
B.h:
class A;
class B : public vector<A>
{
}
#include "A.h"
Unfortunately, if A and B are exported on Windows, MSVC chokes on not having a full defini开发者_开发知识库tion of A when constructing B.
To resolve this I need to store a pointer to B in A. I'd like a wrapper for this, something like boost::scoped_ptr, but that creates a new object in its constructor, and has the same copy semantics as the object it points to. This would take the form:
A.h:
class B;
class A
{
magic_ptr<B> b;
}
B.h:
#include "A.h"
class B : public vector<A>
{
}
Before I go reinventing the wheel, does anyone know if this already exists in STL or boost?
Is boost::shared_ptr what you try to find?
精彩评论