#include <stdio.h>
int temp = 0;
class Test
{
public:
void Start()
{
temp = 20;
};
};
//to class
void (Test::*pt2Func3)(void);
int main()
{
pt2Func3 = &Test::Start;
printf("temp = %d\n",temp);
//create the class we wan't to use with
Test test;
//let's call the function then
(test.*pt2Func3)();
printf("temp = %d\n",temp);
return 0;
}
pointer to diferent member functions
Is it possible , to make a pointer that can point to different member functions ?
I know that I can create a pointer to a member function like that :
But if for example I have 2 different classes and I wan't to make a pointer that can point to any member function in these classes. Can it be done ?
Thanks for any input.
C++ doesn't natively support that kind of pointer. You may want to consider a functor implementation instead such as boost::function.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement