I'm wondering if this is even possible in C++. Here's what I did in java a while back:
class Suit {
public static Suit Hearts = new Suit("Hearts");
public static Suit Clubs = new Suit("Clubs");
public static Suit Diamonds = new Suit("Diamonds");
public static Suit Spades = new Suit("Spades");
private String value;
private Suit(String suit)
{
value = suit;
}
public String getValue()
{
return value;
}
}
After trying many ways to do this in C++, I keep getting back to the error that:
only static const integral data members can be initialized within a class.
I know I could accomplish something similar with an enum Suits {Hearts, Spades, Diamonds, Clubs}
, but I really would like to have the string associated with it.
Does anybody have any idea how to do this?