提交 baf036d9 编写于 作者: 辉哈's avatar 辉哈

为动态多态(晚绑定)例子加上虚析构和delete指针

上级 f11d2f32
......@@ -515,6 +515,7 @@ public:
{
...
}
virtual ~Shape();
};
class Circle : public Shape // 圆形类
{
......@@ -534,6 +535,10 @@ int main()
Shape * shape2 = new Rect(5.0, 6.0);
shape1->calcArea(); // 调用圆形类里面的方法
shape2->calcArea(); // 调用矩形类里面的方法
delete shape1;
shape1 = nullptr;
delete shape2;
shape2 = nullptr;
return 0;
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册