次のように定義されたクラスがあります。
Class A
{
public:
int num;
A *parent;
vector<A *> children;
...
// constructor without parameters
A(void)
{
this->num = 3;
this->parent = 0;
for (int i=0;i<num;++i)
children.push_back(new A(this,num-1));
}
// constructor with parameters
A(A *a,int n)
{
this->num = n;
this->children->parent = a;
for (int i=0;i<num;++i)
this->children.push_back(new A(this,this->num-1));
}
};
これで、コンストラクターは正常に動作します。デストラクタに問題があります。現在、デストラクタは次のように定義されています。
A::~A(void)
{
if (this->parent!=0) this->parent = 0;
for (int i=0;i<(int)children.size();++i)
this->children[i]->~A();
vector <A *> ().swap(this->children);
}
しかし、デバッグするたびに、次の場所で壊れます。
void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
::operator delete(_Ptr);
}
this->children のベクトル内のポインターを削除できないようですが、クラスを正常に分解できる方法はありますか?