Page 1 of 1

problem with a simple class using position2d<s32>

Posted: Mon Jun 18, 2007 1:41 pm
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?

Posted: Mon Jun 18, 2007 2:12 pm
by eneru
you need to instantiate your button before applying methods on it !

=> btntest = new CGButton();

Posted: Mon Jun 18, 2007 2:12 pm
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.