Enums in function parameters

I'm trying to make a function that will take a enum from a class and set it equal to whatever I called in the function. I can't seem to get it to work though.

What I have is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

// Armour.h
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class Armour
{
private:
	string armourName;
	enum armourPiece{gauntlets, greaves, chestplate, helmet, boots, cape};
	enum armourMaterial{fur, leather, iron, steel, chainmail, chainPlate};
	int armourCondition;
	int armourMitigation;	
public:
	void setArmourProperties(armourPiece b); 
	void setArmourProperties(armourMaterial a);
	void setArmourProperties(int ac, int am);
	friend void damageArmour();
};




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

//Armour.cpp
#include "Armour.h"
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

void Armour::setArmourProperties(armourPiece b)
{
	
}

void Armour::setArmourProperties(armourMaterial a)
{

}

void Armour::setArmourProperties(int ac, int am)
{
	armourCondition = ac;
	armourMitigation = am;
}


I can't seem to find what the syntax I need is.
Make the enums public and:

1
2
Armour object;
object.setArmoutProperties(Armour::fur);


Why? Because the enumeration is inside the class-namespace Armour.
Thanks. So when I make a class object I just call the function and insert the class - binary scope operator - then enum value?
That's pretty much it yeah, but you can do something different as well:

1
2
3
// Defined outside the class
enum class Material
{fur, leather, iron, steel, chainmail, chainPlate};


and instead call
 
object.setArmourProperties(Material::fur);
You have no members of types enum armourPiece and enum armourMaterial in the class. So it is not clear why you defined non-static member functions that deal with objects of these types passed as arguments to the functions. I do not see any sense in such class definition.
Last edited on
Thanks again!
Topic archived. No new replies allowed.