I have the following code:
// Piece.h
class Piece
{
public:
enum class Color {BLACK, WHITE};
Piece();
Piece(int x, int y, Piece::Color color);
private:
int m_x;
int m_y;
Piece::Color m_color;
static const int UNINITIALIZED = -1;
};
How do I access the enum from the method functions: (attempt)
// Piece.cpp
Piece::Piece() :
m_x(Piece::UNINITIALIZED),
m_y(Piece::UNINITIALIZED),
m_color(Piece::Color BLACK) // PROBLEM
{}
Piece::Piece(int x, int y, Piece::Color color) :
m_x(x),
m_y(y),
m_color(color)
{}
The Problem:
Piece.cpp: In constructor ‘Piece::Piece()’:
Piece.cpp:8:24: error: expected primary-expression before ‘BLACK’
8 | m_color(Piece::Color BLACK)
I'm new to C++ so this might not be good code practice, but I would generally like to know how to achieve this (and also understand why I shouldn't write like this, if it is in fact bad practice)
Thank you