My single error is that Base class SlotMachine is undefined.
I have no idea how i am getting this error. To my knowledge im defining everything just fine. is the error somewhere else?
This error is not letting me compile and move forward on this.Help is greatly appreciated!
You should define static members outside of ANY curly braces, not inside any function or class definition, just like global variables. Usually you define static members in cpp file of the related class, that is slotmachine.cpp.
In .H file leave as it is:
1 2 3 4 5 6 7 8 9 10
void add_quarters( int quarters );
int check_quarters() const;
and additionaly put definitions in cpp file:
1 2 3 4 5 6 7 8 9
int SlotMachine::m_creditpool = 0;
int SlotMachine::m_rewardpool = 0;
And as a sidenote: is there a real reason to make these variables static? You mean to create many machines of the same type, that would share these variables? Maybe it would be easier to make them normal instance variables, and forget about all the above?
To access class fields from derived class make them protected:, making them static do not affect their privateness.
A quick review: public: - all classes can access these members protected: - only this class and derived classes may access these members private: - only this class may access these members (other classes may use setters and getters, if such exist and are public)
static - each and every object of this class share this field. If you change its value in one object, all objects will be affected. You can access public static fields even if no objects of this class are created.