Original Post
Ok, I spent a long time last night trying to figure this out. Maybe my design is flawed, but I would like to know if what I am trying to do is at least possible.
I have an input class, and I want to be able to load in keymaps etc without having to change the program, so I have decided on this method. Create an input manager class that creates my input object and then calls the update method to gather the keypresses. Fine so far, now I want to pass the Inputmanager class my player object and assign the playerobjects function pointer, at the moment defined as:
void(cInputManager::*pfnKeypress)(TKEYDATA);
I have to declare my cInputManager class in my cPlayer class, which I am not overjoyed about but can live with. All this is so when I call my players move object, it will in turn call the function pointer, update the keypresses and know which of its keys have been pressed. My logic makes sense to me...
Now I am having a problem, I can''t call the function pointer. If I give my cPlayer class a pointer to the cInputManager class I can do this
(inputmanager->*pfnKeypress)(keys);
but woops, I think I am doing something wrong there.. cos it crashes if I call my players move method(which calls the keypress function).
Now again, my design was thought up at about 12:30am last night, so I was a little tired.. I haven''t really had much experience of function pointers, but I knew I couldn''t make my inputmanager functions statics (as they need to call the inputmanagers update). If you can see what I am trying to do, and can suggest a better design then I have no problems with that, if you can help me work out what I am doing wrong, I would be most grateful.
Either way, thank-you for any help you can provide.
=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore
=*=