Skip to main content
gamedev.net
🔒 Locked

function pointer

Started by anupgupta 1 reply 600+ views
Original Post
anupgupta
anupgupta
hello

I have a query as to how to pass a member function from a class via function pointer..
the example is as follows

class CSound
{
public:
void playSound(int index);
void stopSound(int index);

//Memory Allocation Functions
void MemAlloc(int bytes, int use, int actUse);
void MemFree(void *mem);

};

now i call a function which is the part of the API and pass the functions in the CSound class via function pointer to the function...
sndRegisterMainMemAllocator(MemAlloc, MemFree);

but here the compiler always gives me an error..
error 1297: argument of type "void (*) (int , int, int*)" is incompatible with parameter (1 of sndRegisterMainMemAllocator) of type "ExternSndMemAlloc"

...In C i know just passing the name of the function works...but in c++ i am a little confused whether just passing the name of the member function of the class will work...

i also tried making the member functions as static but then too i get the same error...
Please advice on this....as how to get it working...any suggestions would be most helpful...

gameXcore
gameXcore
You may also want to google for "Delegates" for a more robust solution. Personally my favorite type is "impossibly fast delegates".
Game development blog and portfolio: http://gamexcore.co.uk

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.