Storing function pointers in a class?
Hello, the topic pretty much says it all.
I''m curious as to how i''d define a member variable in a class so that I could pass the class a function pointer and it''ll hold that pointer.
Hope someone can help.
- Newb Programmer: Geek++
Pretty much the same way you put any variable in a class.
class ClassWithFunctionPointer { public: typedef void (*void_ptr)(void); void set_function_pointer(void_ptr ptr) { my_pointer = ptr; } private: void_ptr my_pointer;};
Ahh, it''s the having to typedef it that was getting me.
Thanks, works like a charm.
- Newb Programmer: Geek++
Thanks, works like a charm.
- Newb Programmer: Geek++
It''s entirely possible to do it without the typedef - it just looks ugly as sin.
class ClassWithFunctionPointer { public: void set_function_pointer(void (*ptr)(void)) { my_pointer = ptr; } private: void (*my_pointer)(void);};
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement