Undefined reference?

Pages: 12
Do you think this one is a better version than the other one I posted earlier? I changed the union to an enum struct(which is a scoped enum correct?) to make more simple.


1
2
3
4
5
6
7
   struct ARMOR_ELEMENTS {
        enum struct ARMORS {
            STEEL = false,
            IRON = false,
            LEATHER = false,
            TITANIUM = false
        };


It's not better because there is no point in having an enumerated type whose values are all the same. There is no way to differentiate between them.
I made them false because in beginning you start off with no armor. So it's false you have armor. Maybe this one is better?
1
2
3
4
5
6
7
8
 struct ARMOR_ELEMENTS {
        enum struct ARMORS {
            EMPTY = true,
            STEEL = false,
            IRON = false,
            LEATHER = false,
            TITANIUM = false
        };
An enumeration is supposed to be a set of distinct values. You have made several of them equivalent, which I'm sure is not what you really want:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
enum ArmorType {
    EMPTY = true,
    STEEL = false,
    IRON = false,
    LEATHER = false,
    TITANIUM = false
};

// some code
ArmorType myArmor = EMPTY;
// ... person gets some new armor
myArmor = LEATHER;
// later, suppose we need to check their type of armor
if(myArmor == STEEL) {
// returns true!
// This is because you have defined LEATHER and STEEL as being the same value, so they compare equal. 


You might want to re-read a quick description of how to use an enumeration. You'll probably be able to figure out what the problem here is if you haven't already.
Yeah I understand it now, I was thinking I could just change/switch around the values but now I understand that's just more work. So I just assigned them different numbers now. I'll probably reassign the numbers in order from lowest to greatest depending on how good the armor type is. Anyways thanks guys! I'll try and finish this soon maybe today, but yeah.
1
2
3
4
5
6
7
enum struct ARMORS {
            EMPTY = 0,
            STEEL = 1,
            IRON = 2,
            LEATHER = 3,
            TITANIUM = 4
        };
Topic archived. No new replies allowed.
Pages: 12