Effective C++ Chapter6-继承与面向对象设计

2017-04-21  本文已影响0人  寒冰豌豆
32、确定你的public继承塑模出is-a关系
33、避免遮掩继承而来的名称
![image.VI9LXY.png](https://img.haomeiwen.com/i4602306/88bcfbefc4caac36.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
34、
35、考虑virtual函数以外的其他选择
36、
#include <iostream>
using namespace std;

class Shape{
public:
    enum ShapedColor { Red=0,Green,Blue };
    virtual void draw(ShapedColor color = Red)const= 0 ;
    
};

class  Rectangle:public Shape{
public:
    
    void draw(ShapedColor color=Red )const;

};
void Rectangle::draw(ShapedColor color )const
{
    cout << "Recangle class: ";
    cout << color<<endl;
}

int main()
{
    Rectangle r ;
    r.draw();
    Shape*pr = &r;
    pr->draw();
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读