Skip to main content
gamedev.net
🔒 Locked

Function pointers in classes

Started by tool_2046 Oct 26, 2002 at 3:55 PM 1 replies 250+ views
Original Post
tool_2046
tool_2046
Okay, I''m sure this question has been asked a billion times, but I just can''t figure this out. Say I have some class like class SomeClass { public: void (* CurrentFunction)(void); void Init(void); void Blah(void); private: int Data; }; SomeClass Test; And then if you try to say something like CurrentFunction = Init; But then you get some conversion error, so you declare Init and Blah as static: static void Init(void); static void Blah(void); and then this allows you to set CurrentFunction equal to one of these but then static function can''t access any member data of the class. So say then in Init() you want to set Data = 0: void Init(void) { Data = 0; } This gives an error because static functions can''t access member data, nor do they have a this pointer. So then how do you do you have a class when a function pointer in it point to another function in the class so that the function its pointing to can access data in the class? Is this just impossible? I refuse to believe it, someone please help...
Shannon Barber
Shannon Barber
It''s not impossible, it''s just a pita to explain

Someone dropped this link in another thread, perhaps it''s answered there function-pointer.org
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Fruny
Fruny
This thread is a duplicate of #121210

[edited by - Fruny on October 27, 2002 4:52:40 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

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

Sign in to reply to this topic.