前任:
class base
{
public:
base()
{
// allocate memory for basearray
}
virtual ~base()
{
// delete basearray
}
protected:
float* basearray;
};
class derived1 : public base
{
public:
derived1()
{
// allocate memory for derivedarray
}
~derived1()
{
// delete derived array
}
protect:
float* derivedarray;
};
void main()
{
derived1 d;
...
base* pb = &d;
...
// Delete base array?
}
我的基类中有一个虚拟析构函数和一个数组。如果基类析构函数被派生类析构函数覆盖,则基数组不会被删除。什么是好的解决方案?