Skip to main content
gamedev.net
🔒 Locked

pointer to member function?

Started by Case Dec 3, 2002 at 2:16 PM 3 replies 200+ views
Original Post
Case
Case
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
kuphryn
kuphryn
Here is one solution.


  
class XYZ
{
public:
...
void DisplayObject(const unsigned nPos);
};

typedef void (XYZ::*DObjPtr)(const unsigned nPos);

DObjPtr pFunction = &XYZ::DislayObject;


Kuphryn
George2
George2
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
Qw3r7yU10p!
Qw3r7yU10p!
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.