pointer to member function?

Started by
3 comments, last by Case 21 years, 4 months ago
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
Advertisement
Here is one solution.


  class XYZ{public:   ...   void DisplayObject(const unsigned nPos);};typedef void (XYZ::*DObjPtr)(const unsigned nPos);DObjPtr pFunction = &XYZ::DislayObject;  


Kuphryn
here

[edited by - George2 on December 3, 2002 3:30:40 PM]
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon
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.
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.

This topic is closed to new replies.

Advertisement