class MyEventReceiver : public IEventReceiver
{
public:
world *myworld;//my pointer storage
virtual bool OnEvent(SEvent event)
{
}
};
void bla()
{
world myworld;//struct of everysthing
MyEventReceiver receiver;
myworld->device->setEventReceiver(&receiver);
receiver.myworld=myworld;//copy pointer to class
}
I need this because i canot make "myworld" global. But this example makes a copy of "myworld" and dont copys the pointer. Any Ideas?
Hi! if i use "receiver.myworld=&myworld;" instead of "receiver.myworld=myworld;" compiler says: error C2440: '=' : cannot convert from 'world **' to 'world *'
class eventRcv
{
public:
world *myworld;
getWorld(world *w); { myworld = v }
}
//////////
world myBeautifulWorld;
eventRcv receiver;
receiver.getWorld(&myBeautifulWorld);
world myBeautifulWorld; is already a pointer (world *myBeautifulWorld;)
Thats why world *myBeautifulWorld is defined in the header of a function in my script. And i need to give this pointer to the eventreceiver class from this function.
class MyEventReceiver : public IEventReceiver
{
public:
world *myworld;//pointerstorage
virtual bool OnEvent(SEvent event)
{
//at this point i need a pointer to theworld
}
}
void init_world(world *myworld)
{
//myworld is now a pointer to theworld
MyEventReceiver receiver;//now creating the eventreceiver
myworld->device->setEventReceiver(&receiver);
receiver.myworld=&myworld;//copy the pointer to eventreceiver (do not work)
}
world theworld;
init_world(&theworld);
Of course you have to use the passing of the pointer value instead of the adress as you already are working with adresses. But your program won't work as your event receiver will die after the init_world method.
// Include headers
#include <CEventReceiver.h>
// Constructor
CEventReceiver::CEventReceiver()
{
// Set the keypress array to false
for (s32 i = 0; i < KEY_KEY_CODES_COUNT; i++)
{
keys[i] = false;
}
}
// Event handler function
bool CEventReceiver::OnEvent(SEvent Event)
{
// If the event type is a key input event
if (Event.EventType == EET_KEY_INPUT_EVENT)
{
// Set the corresponding value in the array to the state of the key
keys[Event.KeyInput.Key] = Event.KeyInput.PressedDown;
}
// Return false - ensures FPS cameras will still work
return false;
}
// Get key state
bool CEventReceiver::getKeyState(EKEY_CODE key)
{
return keys[key];
}
hybrid wrote:I wonder why this would compile anyway, you have to take the address of the class: receiver.myworld=&myworld;
thats a common mingw problem I believe. but I'm probably wrong about that I'm paying minimul attention really. sry
No, the variable was defined as a pointer, so it was enough to pass the value (a pointer) instead of taking the addresse of a struct (which it was told to be).
And yeah, I will try to eventually give enough information to solve the problem, but I won't do it myself. Except for those who give me money