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!
@JockX
What do you mean define them outside of class?
do you mean i should put them in slotmachine.cpp instead of slotmachine.h?
where? inside slotmachine::slotmachine()? cuz that throws me an error
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
class SlotMachine
{
public:
staticint m_creditpool;
staticint m_rewardpool;
SlotMachine();
int play();
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
#include<stdlib.h>
#include"slotmachine.h"
int SlotMachine::m_creditpool = 0;
int SlotMachine::m_rewardpool = 0;
int SlotMachine::play()
{
//(... etc)
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?
m_creditpool and m_rewardpool were private at first and i was trying to access them from a derived class. apperantly making them static is the only way?
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.