假设我有这个代码
class Base{
public:
int getVal();
private:
int a, b;
};
class Derived::public Base{
public:
void printVal();
};
int main(){
Base *b = new Derived();
delete b;
}
我知道虚拟析构函数会正确删除内容,但是即使派生类中没有虚拟函数且没有数据成员,使用基指针(当没有虚拟析构函数时)删除是否不好?如果这样做会发生什么?