Jump to content
  • Advertisement

Archived

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

afterburn

Function pointers...

This topic is 5331 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

Yes I did a search for it both in the forums and articles. My issue is related to they differences between declaration and the function I am trying assign to it. I have a class that holds all events that is a singleton. However the class that tries to consume this errors on compile time. Saying it doesn''t match the declaration. typedef long(*EventDelegate)(); EventSubSystem *events = EventSubSystem::GetInstance(); Event event; event.event = 0x0001; event.eventFunc = NetworkEvents; //errors here... events->RegisterEvent(event); void NetworkSubSystem::NetworkEvents() { } Not really sure how to resolve this. Is this approach even a good idea?

Share this post


Link to post
Share on other sites
Advertisement
Of course, any function in a class automagically passes the "this" pointer, so the function types are different.

Either make NetworkEvents static, which means you don''t have access to the class members, or look for a way to make the function pointer point to a member of a class.

Share this post


Link to post
Share on other sites
Pointer to member function syntax:

class Foo { public: long Bar(); };
typedef long (Foo::*pmf)();

Foo foo, *pfoo;
pmf ptr = &Foo::Bar;

foo.*ptr();
pfoo->*ptr();


foo.*ptr and pfoo->*ptr) cannot be manipulated in any way beside being called. You have to store the object and the pointer-to-member separately (add a new field to your Event type).

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!