#include <iostream> using namespace std;class Point { public:Point(double a = 0, double b = 0){ x = a; y = b; } ~Point(){ cout << "Executing Point destructor \n";} private: double x; double y; }; class Circle: public Point { public:Circle(double a=0, double b=0, double c=0):Point(a,b), radius(c){} ~Circle(){cout<<"executing Circle destructor"<<endl;}private: double radius; };int main(){ Point * p = new Circle(1, 1, 4); delete p; return 0; }
执行的结果是:
Executing Point destructor
但我把派生类的构造函数:
Circle(double a=0, double b=0, double c=0):Point(a,b), radius(c){}
改成
Circle(double a=0, double b=0, double c=0){ Point(a,b); radius = c; }
运行结果是:
Executing Point destructor Executing Point destructor
慕码人8056858
相关分类