考虑下面这段程序:
#include <iostream>
using namespace std;
class Shape {
public:
enum ShapeColor { Red, Green, Blue };
virtual void draw(ShapeColor color = Red) const = 0;
};
class Rectangle : public Shape {
public:
virtual void draw(ShapeColor color = Green) const {
cout << "Rectangle::draw, color = " << color << endl;
}
};
class Circle : public Shape {
public:
virtual void draw(ShapeColor color) const {
cout << "Circle::draw, color = " << color << endl;
}
};
int main()
{
/*
Circle circle;
circle.draw(); //编译出错
*/
/*
Shape *pc = new Circle;
pc->draw(); //color = 0(Red)
*/
/*
Rectangle rtg;
rtg.draw(); //color = 1(Green)
*/
/*
Shape *pr = new Rectangle;
pr->draw(); //color = 0(Red)
*/
return 0;
}
#include <iostream>
using namesp