为什么我的 不能析构coordinate 他析构了circle~
#include<bits/stdc++.h>
using namespace std;
class shape{
public:
shape(){
cout<<"shape"<<endl;
}
virtual ~shape(){
cout<<"~shape"<<endl;
}
virtual double calc(){
cout<<"calc"<<endl;
return 0;
}
};
class coordinate{
public:
coordinate(int x,int y){
cout<<"coordiante"<<endl;
m_x=x,m_y=y;
}
~coordinate(){
cout<<"~coordiante"<<endl;
}
protected:
int m_x,m_y;
};
class circle:public shape
{
public:
circle(double r){
m_r=r;
cout<<"circle"<<endl;
coordinate *m_p=new coordinate(3,5);
}
virtual ~circle(){
cout<<"~circle"<<endl;
delete m_p;
m_p=NULL;
}
double calc(){
cout<<"circle->calc"<<endl;
cout<<m_r*m_r*3.14<<endl;
return 0;
}
protected:
double m_r;
coordinate *m_p;
};
int main(){
circle *p=new circle(3);
delete p;
p=NULL;
return 0;
}