Archived

This topic is now archived and is closed to further replies.

wyrd

Pointer to function problem.

Recommended Posts

I should note that the code works with functions that are not inside classes. The error is when I try to pass a function that''s inside a class (it''s a public function). I''m new to function pointers (to say the least), so I''m clueless as to what''s going on here. Function defintion which takes function pointer; void CGameWindow::SetClickEvent(void (*pfCallback)(CGameWindow*)) Function declaration that I''m trying to pass; (Note; public function in CGameApp) void Bet_Event(CGameWindow* pWindow); Code that attempts to pass Bet_Event to SetClickEvent; m_betOptions.SetClickEvent(this->Bet_Event); Error: error C2664: ''CGameWindow::SetClickEvent'' : cannot convert parameter 1 from ''void (CGameWindow *)'' to ''void (__cdecl *)(CGameWindow *)'' Thanks in advance.

Share this post


Link to post
Share on other sites
You can't pass a member function [ edit ] like that [ / edit ]. Options that will work: making the member function you want to pass, a friend or static member function, or try using functors.

http://linuxquality.sunsite.dk/articles/memberpointers/

[edited by - EL on January 25, 2004 4:07:13 PM]

Share this post


Link to post
Share on other sites
Hmm.. wasn''t really the answer I was hoping for.

Thanks for the responses and link. I''ll just use friend functions for now and have my CGameWindow return a void* pointer to an owner.

Share this post


Link to post
Share on other sites