Enum Help

I have done a lot of searching online for help with enums, I have found none that apply to this situation. I'm trying to make a simple single player RPG game. Right now I am in the stage of developing the items and the crafting. My problem is this:
1
2
3
4
5
6
7
8
struct Item{
	string Name;
	int BuyPrice;
	int SellPrice;
	int WeaponDamage;
	bool Equippable;
	enum ItemType {Type1 = 0,Type2 = 1,Type3 = 2};
};

When I try to apply the enum to the actual items, which are saved in Items.h(not main.cpp in case it matters) I get the error saying there are too many initializers. please help, and thank you for reading
There isn't anything wrong with the enum itself, though there is no reason to manually assign values to ItemType - enum already does that for you. Where exactly do you get your error?
I'm getting the error in Items.h, I think that I know what my error is but I don't know why it is occuring. When I had the enum as the last value in the Items such as
Item Log = {"Log",10,5};
it was telling me that there were to many initializer values. When I started moving onto the next set of items:EquippableItem WoodenSword = {"WoodenSword",35,17,2,0,false};
I'm getting the same error, but on the bool that says if the Item is equipped or not. The constructors are acting as if there is one less value in the struct?
I don't believe that this is the best fix to the problem, but in the struct I added a useless int named SpaceTaker. This extra int allows for the input of the last necessary values. I still would like to know why the struct would do this.
Short question: Why do you have an ItemType enum anyways? You do realize that is just a type declaration and not a data field, right?
The enum was being used to tell if the item was craftable, smeltable, etc. I'm very new to enums so I don't believe that I need this enum. I thought it would be more efficient to do the crafting with an ItemType enum, however I can merely do it Name based.
1
2
3
4
5
6
7
8
9
struct Item{
        enum ItemType {Type1 = 0,Type2 = 1,Type3 = 2};
	string Name;
	int BuyPrice;
	int SellPrice;
	int WeaponDamage;
	bool Equippable;
        ItemType type;
};


?

PS: This:
1
2
3
4
5
6
7
8
9
10
struct Item{
	std::string Name;
	int BuyPrice;
	int SellPrice;
	int WeaponDamage;
	bool Equippable;
	enum ItemType {Type1 = 0,Type2 = 1,Type3 = 2};
};

Item item = {"name", 10, 15};


Compiles just fine for me.
Put all of the values into the constructor and see if it still compiles
Yes it does.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <string>

struct Item{
        enum ItemType {Type1 = 0,Type2 = 1,Type3 = 2};
	std::string Name;
	int BuyPrice;
	int SellPrice;
	int WeaponDamage;
	bool Equippable;
	ItemType type;
};

Item item = {"name", 10, 15, 12, true, Item::Type1};

int main()
{
return 0;
}


You are doing something wrong with your code.
Topic archived. No new replies allowed.