Jump to content
  • Advertisement

Archived

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

wyrd

Pointer to function problem.

This topic is 5233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!