i'm recently starting with c++ and I'm having troubles when I want to use a c++ class like Java's enums. I would have the 'simulated enum' class attribute, but when I try to initialize the attribute in the constructor i received the following error:
no default constructor exists for model::suite
I now I have the constructor private, but the enum should have private constructors to prevent the construction of undefined objects of that class.
¿What should I do?
e.g.
suite.h
#include <iostream>
#include <string>
#include <vector>
namespace model
{
class Suite
{
public:
static const Suite CLUBS;
static const Suite DIAMONDS;
static const Suite SPADES;
static const Suite HEARTS;
static const int SIZE = 4;
private:
std::string name;
Suite(std::string name)
{
this->name = name;
}
public:
std::string toString()
{
return name;
}
std::vector<Suite> values()
{
return {Suite::CLUBS, Suite::DIAMONDS, Suite::SPADES, Suite::HEARTS};
}
};
const Suite Suite::CLUBS = Suite("CLUBS");
const Suite Suite::DIAMONDS = Suite("DIAMONDS");
const Suite Suite::SPADES = Suite("SPADES");
const Suite Suite::HEARTS = Suite("HEARTS");
}
card.h
#pragma once
#include <string>
#include "suite.h"
#include "face.h"
namespace model
{
class Card
{
public:
Card(int face, int suite);
Face getFace();
Suite getSuite();
bool isMergeable();
std::string toString();
private:
Face face;
Suite suite;
bool isRed();
bool isContigous(Card card);
};
}
card.cpp
#include <iostream>
#include "card.h"
using namespace std;
using namespace model;
Card::Card(int face, int suite)
{
this->face = Face::VALUES[face];
}
Face Card::getFace()
{
}
Suite Card::getSuite()
{
}
bool Card::isMergeable()
{
}
std::string Card::toString()
{
}
bool Card::isRed()
{
}
bool Card::isContigous(Card card)
{
}