class DeckOfCards
{
public:
const int SEEDS = 4;//can I declare here a const?
const int FACES = 13;//non-static data member available only with std c++11//what is the solution?Why?
DeckOfCards();
~DeckOfCards();
void printA(const int deck[SEEDS][FACES]);
void distribute(const int deck[SEEDS][FACES], const char** seeds, const char** faces);
void mix(int deck[SEEDS][FACES]);
};
Because initialization non-static constant members in class declaration wasn't allowed before C++11.
what is the solution?
Compile in C++11 mode. Or move value initialization to the class definition or constructor. Or make variable static, it will fix errors with your functions as well.
Thank you very much!!!
I didn't know we have to do so, I thought was more reasonable do like I did: accessing through the object and not the class directly...
This is just for const variables or what?
In C++, when a class member (data or function) is declared as static, it means that there is one single instance of that member that is shared between all instances of the class. Those static members exist independently of any particular instance of the class. In fact, they exist and can be used, even if no objects of that class have been instantiated!
That's why you access them using the name of the class, not the name of a specific object.
As you might imagine, the rules for how you define and use static members are different from those for non-static members. But that's something you can look up - I'm not going to re-write a textbook here :)