dimanche 3 février 2019

How to correctly create, initialize and access to a static member of a class?

I'm making a poker game and I have a class which contains a std::map to assign a value for every card on the poker deck referring to its name. I tried to put it as a component of another class as static member, since I have to assign a value every time a card is created, but for some reason when I try to access to it I get compiler error undefined symbol or duplicated symbol.

My partial solution have been declaring the class container as a global variable outside a class scope, but I know it's a bad practice , and if not there is anyway my doubt.

extern Baraja baraja;

For some reason when I declare this as static member or static const member, happens that I cannot access to the values of the std::map or I get compiler error undefined symbol or duplicated symbol so as I have searched in web documentations and cannot find a reason or solution I have this question.

How to correctly create, initialize and access to a static member of a class?

Aucun commentaire:

Enregistrer un commentaire