我有一个基类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);
}
enum Color
我想向我的构造函数添加一个参数,这样我就可以在我的基类中使用形状的颜色。我怎样才能做到这一点?我还想将颜色打印为string
. 我不知道如何enum
在构造函数中用作参数。
任何帮助表示赞赏...