我使用几个枚举类型实例化一个对象,并试图设置一些基于这些枚举类型的字符串成员。但是,当我正在调试和步骤时,用于设置字符串的开关触及每个事件,并且每个字符串都被设置为每个枚举类型的最后一种情况。C++枚举到字符串开关不工作
enum Number {
one,
two,
three
};
enum Color {
purple,
red,
green
};
enum Shading {
solid,
striped,
outlined
};
enum Shape {
oval,
squiggle,
diamond
};
Card::Card(Number num, Color colour, Shading shade, Shape shaper) {
number_ = num;
color_ = colour;
shading_ = shade;
shape_ = shaper;
setStrings();
}
void Card::setStrings() {
switch (number_) {
case one:
number_string = "one";
case two:
number_string = "two";
case three:
number_string = "three";
}
switch(color_) {
case purple:
color_string = "purple";
case red:
color_string = "red";
case green:
color_string = "green";
}
switch (shading_) {
case solid:
shading_string = "solid";
case striped:
shading_string = "striped";
case outlined:
shading_string = "outlined";
}
switch (shape_) {
case oval:
shape_string = "oval";
case squiggle:
shape_string = "squiggle";
case diamond:
shape_string = "diamond";
}
}
每卡我用实例化重载的构造函数具有NUMBER_STRING = “三国”,COLOR_STRING = “绿色”,shading_string = “概述”,并shape_string = “钻石”。
它永远不会是一个突破,但我需要休息 –
如果你不使用休息,这将永远是一个贯穿始终。 – user902384