pointer to member function?
lo,
I know I can create a pointer to a normal function but, does anyone know if there''s any way to create a pointer to a member function?
Cheers,
Case
Here is one solution.
Kuphryn
class XYZ{public: ... void DisplayObject(const unsigned nPos);};typedef void (XYZ::*DObjPtr)(const unsigned nPos);DObjPtr pFunction = &XYZ::DislayObject;
Kuphryn
don''t forget - member functions are members of an object. so you have to associate an object with the function pointer before you can call it.
the only exception is static member functions which don''t use any member data so don''t need an object (and don''t get a ''this'' pointer passed to them)
the function-pointer link should do you fine.
the only exception is static member functions which don''t use any member data so don''t need an object (and don''t get a ''this'' pointer passed to them)
the function-pointer link should do you fine.
Cheers ppl. I''d figured out the first bit of declaring the pointer, but I hadn''t figured out to associate the pointer with an instance using something like:
myInstance.*myPointer(...);
That link was very helpful, George2. Thanks. I''m sure that stuff wasn''t in my Deitel&Deitel book... oh well.
Case.
myInstance.*myPointer(...);
That link was very helpful, George2. Thanks. I''m sure that stuff wasn''t in my Deitel&Deitel book... oh well.
Case.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement