   [C++] defining constants without define
  Hi everybody!I was a programmer until 4 years ago, when I stopped my career to go to medial school. But then after all this time I've missed my programming and started a new project as a hobby. It's a 2D game built from scratch, in linux, using SDL and C++.After all this time I forgot a lot of the C++ "good practices" and I need help with a "constant" problem:I want to create a type that will contain different constants that will be used to identify the state of a player, like: "attacking", "moving" and "jumping". Then this type will be used to define the current state of the player by calling a function like Do(state):Example:const int GE_PLAYER_ATTACK = 0x00000001;const int GE_PLAYER_MOVE = 0x00000002;const int GE_PLAYER_JUMP = 0x00000004;main(){... player->Do(GE_PLAYER_ATTACK);...}But i want type safety for this "Do" function, so it would be declared like:class Player{ public: void Do(GEPlayerAction action);}My problem is what is the best practice to create this GEPlayerAction type?Maybe I could use an enum, but the sequence isn't linear since I will use bitwise operations to define some status, like: jump+attack => GE_PLAYER_JUMP | GE_PLAYER_ATTACK.Any thoughts?Thank you.
  I guess it was the obvious choice anyway... lol... I was just wondering if there was a more "elegant" way but I guess I will stick with that. I'm trying to make this code following every standard of good programming practice I know to get the best re-usability, so that's why my concern.   ;  how about something like this :namespace GEPlayerAction{const int GE_PLAYER_ATTACK = 0x00000001;const int GE_PLAYER_MOVE = 0x00000002;const int GE_PLAYER_JUMP = 0x00000004;};  You could always use an enumeration...public enum GEPlayerAction {Attack = 0x00000001,Move = 0x00000002,Jump = 0x00000003};Quote:Original post by enigmatixYou could always use an enumeration...*** Source Snippet Removed ***Yes, if you strip out the "public" keyword. :) The values of enum constants need not be continuous.;Quote:Original post by Concentratehow about something like this :namespace GEPlayerAction{const int GE_PLAYER_ATTACK = 0x00000001;const int GE_PLAYER_MOVE = 0x00000002;const int GE_PLAYER_JUMP = 0x00000004;}I've tried this before but I couldn't use GEPlayerAction as a type in the function prototype:void Do(GEPlayerAction action); // doesn't compileFor now I am using the enum, but I'm still thinking if there is a better solution.   ;Quote:Original post by WindryderQuote:Original post by enigmatixYou could always use an enumeration...*** Source Snippet Removed ***Yes, if you strip out the "public" keyword. :) The values of enum constants need not be continuous.Bah... Wasn't thinking when I wrote that. In any case, enumerations are probably the most elegant solution. Also as Windryder stated, you can give them whatever value you want, so long as its an integer.   ;Quote:Original post by ppetruzalekFor now I am using the enum, but I'm still thinking if there is a better solution.This is your solution. Enums were designed to solve this problem.;  Thank you all for your support. Forgive me if the question was too obvious but I'm very rusted in my programming skills.   ;Quote:Original post by ppetruzalekThank you all for your support. Forgive me if the question was too obvious but I'm very rusted in my programming skills.Nothing to be a ashamed of. Good luck. :)   