Skip to content

Commit

Permalink
为动态多态(晚绑定)例子加上虚析构和delete指针
Browse files Browse the repository at this point in the history
  • Loading branch information
huihut committed May 2, 2018
1 parent f11d2f3 commit baf036d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ public:
{
...
}
virtual ~Shape();
};
class Circle : public Shape // 圆形类
{
Expand All @@ -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;
}
```
Expand Down

0 comments on commit baf036d

Please sign in to comment.