我有两个班级,有循环扶养问题:
- 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"
不幸的是,如果A和B在Windows出口,MSVC的cho子在构造B时没有完全的A定义。
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>
{
}
在我重新发明轮椅之前,没有人知道这在STL中是否已经存在或有所加强?