Function pointers...
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?
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.
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.
Pointer to member function syntax:
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).
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).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement