Function pointers??

Started by
2 comments, last by Drki 23 years, 9 months ago
I''m traying to use a function pointer who points to the class fonctions. This is a first example of code that works(without casses): void draw2() { return; } void (*cur_function2)() = draw2; and this is a second part that desent work. Why not? Will it ever work? CConsole console; //class void Cconsole::draw() { return; } void (*cur_function)() = console.draw; //err -> ''initializing'' : cannot convert from '''' to ''void (__cdecl *)(void)'' Thanks.
Advertisement
If you want a function pointer to a class member, this is the syntax:

    class CConsole{   ...   public:       void draw() { ... }};CConsole console;void (CConsole::*ptr)() = &console.draw    


(You might not need the & on console.draw.)
you could also make the class function a friend like
class someclass{
friend somefunction();

};

someclass::somefunction(){

}
then you can make a function pointer to it I belive, but the post above does it better

Im Always Bored
--Bordem
ICQ: 76947930
Im Always Bored--Bordem ICQ: 76947930
See C++ converts the member functions into function pointers internally with the first parameter as the pointer to the class itself. You will understand this concept if u try to understand programming DirectX in C and C++ (differenc). In C u use the lpvtbl array.
For the problem the above solutions are fine.

There is no problem so complicated that it cannot be complicated further.

This topic is closed to new replies.

Advertisement