我有一个基类Shape
和一些其他派生类,如Circle
,Rectangle
等。将enum传递给构造函数
这是我的基类
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
作为参数。
任何帮助表示赞赏...
我认为你不应该使枚举颜色私人。 – 2012-07-24 03:16:53
你目前的构造函数是怎样的?我也怀疑你可以实现这个目标,因为enum Shape :: Color是private。 – iammilind 2012-07-24 03:17:26
@iammilind我刚刚添加了我的构造函数 – 2012-07-24 03:24:50