I got a problem when I want to pass an enum value to a default construtor. My enums are defined like this:
typedef enum
{
DOUBLOON,
VICTORYPOINT
} ENUMchipType;
They are stored in a separate .h file.
But when i try to do this:
chips m_doubloon(DOUBLOON);
I get the following error:
error: C2061: syntax error : identifier 'DOUBLOON'
The code for the default constructor is:
chips::chips(
ENUMchipType chipType = DOUBLOON,
int amountValue1 = 0,
int amountValue5 = 0,
QObject *parent = 0) :
m_chipType(chipType),
m_chipCountValue1(amountValue1),
m_chipCountValue5(amountValue5),
QObject(parent) {}
Anyone an idea what is wrong with this piece of code? Thanks in advance!
Edit: I already tried putting the enum is a class als a public member and derive the chips class from it, but without any succes.
EDIT 2: This piece of code reproduces the error in Visual Studio 2013
#include <string>
using namespace std;
//enums.h
typedef enum
{
DOUBLOON,
VICTORYPOINT
} ENUMchipType;
typedef enum
{
PLAYER1,
PLAYER2,
PLAYER3,
PLAYER4,
PLAYER5
} ENUMplayer;
// In chips.h
class chips
{
private:
int m_chipCountValue5;
int m_chipCountValue1;
ENUMchipType m_chipType;
public:
explicit chips(
ENUMchipType chipType = ENUMchipType::DOUBLOON,
int amountValue1 = 0,
int amountValue5 = 0);
ENUMchipType getChipType() const { return m_chipType; }
};
// Chips.cpp
chips::chips(ENUMchipType chipType, int amountValue1, int amountValue5) :
m_chipType(chipType),
m_chipCountValue1(amountValue1),
m_chipCountValue5(amountValue5) {}
// PLayer.h
class player
{
private:
ENUMplayer m_ID;
string m_name;
public:
chips m_doubloon(DOUBLOON);
chips m_victoryPoints(VICTORYPOINT);
explicit player(ENUMplayer ID = PLAYER1, string name = "");
void setName(string name = "") { m_name = name; }
void setID(ENUMplayer ID) { m_ID = ID; }
string getName() const { return m_name; }
ENUMplayer getID() const { return m_ID; }
};
//player.cpp
player::player(ENUMplayer ID, string name) :
m_ID(ID),
m_name(name) {}
int main() {
return 0;
}