Page 1 of 1

non_lazy_ptr problem

Posted: Mon May 30, 2011 6:30 pm
by Esler
hi, i was coding my static keyboard class

Code: Select all

#ifndef _InputControl
#define _InputControl
#include "includes.h"

namespace InputControl{
	class Pressed{
	public:
			static bool R, L;
			static bool Up, Down, Left, Right;
			static bool Menu, Attack, Dash, Jump;
	};
	class Hold{
	public:
			static bool R, L;
			static bool Up, Down, Left, Right;
			static bool Menu, Attack, Dash, Jump;
	};
	class Released{
	public:
			static bool R, L;
			static bool Up, Down, Left, Right;
			static bool Menu, Attack, Dash, Jump;
	};
	class Control{
		public:
			void KeyStatus(bool Key, bool &Pressed, bool &Hold, bool &Released);
			void ReadKeys(sf::Event TheEvent);
	};
}
and i implemented it like that

Code: Select all

#include "InputControl.h"

using namespace InputControl;


void Control::ReadKeys(sf::Event TheEvent){
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::Right, Pressed::Right, Hold::Right, Released::Right);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::Left, Pressed::Left, Hold::Left, Released::Left);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::Up, Pressed::Up, Hold::Up, Released::Up);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::Down, Pressed::Down, Hold::Down, Released::Down);
	
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::K, Pressed::R, Hold::R, Released::R);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::L, Pressed::L, Hold::L, Released::L);
	
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::Space, Pressed::Jump, Hold::Jump, Released::Jump);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::X, Pressed::Menu, Hold::Menu, Released::Menu);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::C, Pressed::Attack, Hold::Attack, Released::Attack);
	KeyStatus(sf::Event::KeyPressed && TheEvent.Key.Code == sf::Key::Z, Pressed::Dash, Hold::Dash, Released::Dash);
	
}
void Control::KeyStatus(bool Key, bool &Pressed, bool &Hold, bool &Released){ //Get key as reference and modify it
	if(Key == true && Pressed == true){Hold = true; Pressed = true; Released = false;} //Held
	else if(Key == true && Pressed == false){Hold = false; Pressed = true; Released = false;} //Pressed
	else if(Key == false && Pressed == true){Hold = false; Pressed = false; Released = true;} // Released
}
It dont work, it returns to me

Code: Select all

  "InputControl::Pressed::Left", referenced from:


      __ZN12InputControl7Pressed4LeftE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed4LeftE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed4LeftE$non_lazy_ptr)


  "InputControl::Pressed::Right", referenced from:


      __ZN12InputControl7Pressed5RightE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed5RightE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed5RightE$non_lazy_ptr)


  "InputControl::Hold::Right", referenced from:


      __ZN12InputControl4Hold5RightE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold5RightE$non_lazy_ptr)


  "InputControl::Pressed::Menu", referenced from:


      __ZN12InputControl7Pressed4MenuE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed4MenuE$non_lazy_ptr)


  "InputControl::Pressed::Up", referenced from:


      __ZN12InputControl7Pressed2UpE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed2UpE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed2UpE$non_lazy_ptr)


  "InputControl::Pressed::Jump", referenced from:


      __ZN12InputControl7Pressed4JumpE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed4JumpE$non_lazy_ptr)


  "InputControl::Released::Left", referenced from:


      __ZN12InputControl8Released4LeftE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released4LeftE$non_lazy_ptr)


  "InputControl::Hold::L", referenced from:


      __ZN12InputControl4Hold1LE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold1LE$non_lazy_ptr)


  "InputControl::Pressed::Dash", referenced from:


      __ZN12InputControl7Pressed4DashE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed4DashE$non_lazy_ptr)


  "InputControl::Hold::R", referenced from:


      __ZN12InputControl4Hold1RE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold1RE$non_lazy_ptr)


  "InputControl::Hold::Up", referenced from:


      __ZN12InputControl4Hold2UpE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold2UpE$non_lazy_ptr)


  "InputControl::Released::Menu", referenced from:


      __ZN12InputControl8Released4MenuE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released4MenuE$non_lazy_ptr)


  "InputControl::Hold::Attack", referenced from:


      __ZN12InputControl4Hold6AttackE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold6AttackE$non_lazy_ptr)


  "InputControl::Hold::Down", referenced from:


      __ZN12InputControl4Hold4DownE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold4DownE$non_lazy_ptr)


  "InputControl::Pressed::L", referenced from:


      __ZN12InputControl7Pressed1LE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed1LE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed1LE$non_lazy_ptr)


  "InputControl::Released::Jump", referenced from:


      __ZN12InputControl8Released4JumpE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released4JumpE$non_lazy_ptr)


  "InputControl::Released::Dash", referenced from:


      __ZN12InputControl8Released4DashE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released4DashE$non_lazy_ptr)


  "InputControl::Released::L", referenced from:


      __ZN12InputControl8Released1LE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released1LE$non_lazy_ptr)


  "InputControl::Pressed::R", referenced from:


      __ZN12InputControl7Pressed1RE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed1RE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed1RE$non_lazy_ptr)


  "InputControl::Released::R", referenced from:


      __ZN12InputControl8Released1RE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released1RE$non_lazy_ptr)


  "InputControl::Released::Right", referenced from:


      __ZN12InputControl8Released5RightE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released5RightE$non_lazy_ptr)


  "InputControl::Pressed::Down", referenced from:


      __ZN12InputControl7Pressed4DownE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed4DownE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed4DownE$non_lazy_ptr)


  "InputControl::Hold::Left", referenced from:


      __ZN12InputControl4Hold4LeftE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold4LeftE$non_lazy_ptr)


  "InputControl::Pressed::Attack", referenced from:


      __ZN12InputControl7Pressed6AttackE$non_lazy_ptr in WorldMenu.o


      __ZN12InputControl7Pressed6AttackE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl7Pressed6AttackE$non_lazy_ptr)


  "InputControl::Released::Up", referenced from:


      __ZN12InputControl8Released2UpE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released2UpE$non_lazy_ptr)


  "InputControl::Hold::Menu", referenced from:


      __ZN12InputControl4Hold4MenuE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold4MenuE$non_lazy_ptr)


  "InputControl::Released::Attack", referenced from:


      __ZN12InputControl8Released6AttackE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released6AttackE$non_lazy_ptr)


  "InputControl::Released::Down", referenced from:


      __ZN12InputControl8Released4DownE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl8Released4DownE$non_lazy_ptr)


  "InputControl::Hold::Jump", referenced from:


      __ZN12InputControl4Hold4JumpE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold4JumpE$non_lazy_ptr)


  "InputControl::Hold::Dash", referenced from:


      __ZN12InputControl4Hold4DashE$non_lazy_ptr in InputControl.o


     (maybe you meant: __ZN12InputControl4Hold4DashE$non_lazy_ptr)


ld: symbol(s) not found


collect2: ld returned 1 exit status


Anyone know what is this?

Re: non_lazy_ptr problem

Posted: Mon May 30, 2011 7:02 pm
by Falco Girgis
You haven't actually allocated any of your static member variables...

In C++, the in-class declaration of static member variables does not actually allocate space for them... otherwise you would have the compiler creating duplicate symbols in every file including that particular header file...

So C++ requires you allocate them yourself in the corresponding .cpp for the header file. Add this to InputControl.cpp:

Code: Select all

bool Pressed::R, Pressed::L, Pressed::Up, Pressed::Down, [..];
bool Hold::R, Hold::L, [..] ;
bool Released::R, Released::L, [..];
As far as memory allocation is concerned, static member variables are allocated/initialized as global variables.

Re: non_lazy_ptr problem

Posted: Mon May 30, 2011 7:17 pm
by Esler
Thanks GyroVorbis.
It is working now.
I'm trying to port my psp code to sfml.
After that i want to use my basic class to generate (again) one psp code and in the future one dreamcast code.

Hey gyro, could you tell me some good dreamcast games, i bought mine not so long ago.