我有一个基类Shape
和一些派生类,如Circle
、Rectangle
等。
这是我的基类。
class Shape {
private:
enum Color {
Red,
Orange,
Yellow,
Green
};
protected:
int X;
int Y;
// etc...
};
这是我的一个派生类之一。
class Rectangle : public Shape {
private:
int Base;
int Height;
string shapeName;
//etc...
};
这是我调用构造函数的方式:
Rectangle R1(1, 3, 2, 15, "Rectangle 1");
我的构造函数:
Rectangle::Rectangle(int x, int y, int B, int H, const string &Name)
:Shape(x, y)
{
setBase(B);
setHeight(H);
setShapeName(Name);
}
我希望在我的构造函数中添加一个参数,这样我就可以在我的基类中使用枚举颜色
传递形状的颜色。我还想将颜色打印为字符串
。我不知道如何在构造函数中使用枚举
作为参数。
感谢您的任何帮助...