samedi 6 mai 2017

Enum class and ==?

I have a problem using enum class on Visual Studio 2015.

Here is my enum class :

enum class Color {
    RED, BLACK
};
enum class WinCondition {
    HIGHER, EQUAL, LOWER
};

Now I got a class Card as well, using a Color as a private value. I'd like to compare one card to another following a few set of rules :

WinCondition Carte::better(Carte c)
{
    if (value > c.getValue())
        return WinCondition::HIGHER;

    if (value < c.getValue())
        return WinCondition::LOWER;

    if (color == Color::RED && c.getColor == Color::BLACK)
        return WinCondition::HIGHER;

    if (color == Color::BLACK && c.getColor == Color::RED)
        return WinCondition::LOWER;

    return WinCondition::EQUAL;
} 

But the compiler refuse the == operator saying

Erreur C2677 '==' binaire : no global operator foundaccepting color type

It's actually a translation for french (sorry if it's not really correct).

Have a great day and keep smiling ! Yaël

Aucun commentaire:

Enregistrer un commentaire