problem with a simple class using position2d<s32>

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
allked
Posts: 12
Joined: Mon Oct 02, 2006 3:44 am

problem with a simple class using position2d<s32>

Post by allked »

i write a simple class for test

button.h

Code: Select all

#ifndef  PART_CGButton
#define PART_CGButton
#include "irrlicht.h"
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
using namespace scene;
using namespace io;

namespace CGGUI
{
	

class CGButton
{
public:
	void setPosition(position2d<s32> pos); 
	    

         position2d<s32> ButtonPos;
		
	     rect<s32> ButtonRect;
	

};


} 
#endif 
button.cpp

Code: Select all

#include "Button.h"

namespace CGGUI
{

void CGButton::setPosition(position2d<s32> pos)
{
ButtonPos=pos;
	
}
} //
when i create this class with
CGButton* btntest;
then i set

btnTest->setPosition(position2d<s32>(23,23));


it complies ok.but when i run program it crashed, when i comment this line it works fine
//btnTest->setPosition(position2d<s32>(23,23));
what happened?
eneru
Posts: 40
Joined: Tue Apr 10, 2007 8:38 am

Post by eneru »

you need to instantiate your button before applying methods on it !

=> btntest = new CGButton();
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You dereference an uninitialized pointer. You should not define a pointer and access the object this pointer might point to sometimes before assigning the object.
Post Reply