#include<iostream>
using namespace std;
class Mahesh
{
public:
Mahesh(){
cout<<"Base Constructor is called at here"<<endl<<endl;
}
virtual ~ Mahesh()
{
cout<<"Base Destructor is called"<<endl<<endl;
}
};
class Purnima:public Mahesh
{
public:
Purnima()
{
cout<<"Derived class constructor"<<endl<<endl;
}
~Purnima(){
cout<<"Derived class Destructor"<<endl<<endl;
}
};
int main()
{
Mahesh *m1;
Purnima p1;
m1=&p1;
return 0;
}
거의 작동?생략 키워드는 아직도 내가 다음 코드 위의 소멸자 앞에 키워드 <code>virtual</code>를 작성하지 않는 경우 내 질문은 다음, 왜 가상 소멸자 잘 작동합니다
더 나은 복제본 : https://stackoverflow.com/q/461203/501250 – cdhowie
복제본이 적절하지 않습니다. 해답은 파생 된 소멸자에서 다시 지정하는지 여부에 관계없이 '가상'이 상속된다는 것입니다. – EJP
소멸자를 다형 적으로 호출조차하지 마십시오. 근본적으로 파생 클래스를 파기하면 부모 파생 클래스와 파생 클래스가 파기됩니다. – chris