static variabls in base class

closed account (zwA4jE8b)
I have this game objects class, and I need a static variabls 'jumping'.
This is becuase multiple derived classes need to know if 'jumping' is true or false.

I am getting the error "undefined reference to game_objects::jumping" when i try to access it from derived classes.

Can anyone give me an example of how I can access jumping from a derived class?
Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class game_objects
{
	protected:
		//Velocity of the objects movement
		float x_vel, y_vel;

		//Sprite sheet info
		int frame_x, frame_y;
		int frame_width, frame_height;

		//Framerate stuff
		int frame, frame_count;
		double fi, ftr;

		//Attributes
		int lives;
		int health;

		//The characters sprite sheet
		SDL_Surface* object;

		//The object type 'b'-bullet 'p'-player 'n'-npc
		char type;
                            static bool jumping;

	public:
		//Character position
		_position position;

		virtual SDL_Rect get_frame();
		virtual SDL_Rect get_bounds();
		virtual void handle_input(Uint8* keystate);
		virtual void update(float dtime);
		virtual void show(SDL_Surface* screen)=0;
		virtual void set_xy(int x, int y);
		virtual float get_y();
		virtual int get_lives();
		virtual void set_lives(int life);
		virtual int get_health();
		virtual void set_health(int heal);
		virtual char get_type();
		virtual ~game_objects(){}
};
Last edited on
You need to instantiate 'jumping'.

Put this globally in one and only one cpp file:

 
bool game_objects::jumping = false;
closed account (zwA4jE8b)
Thank you,

Every derived class is in the same cpp file, So should I just put it globally in that cpp?

Nevermind, I got it, than you very much
Last edited on
Hi ,
How are you using jumping variable in the derived class , can you just past that code also .
Will you not require static function to access static variable ?
Last edited on
Topic archived. No new replies allowed.