Skip to content

Instantly share code, notes, and snippets.

@silv3rm00n
Created December 27, 2011 14:38
Show Gist options
  • Save silv3rm00n/1523838 to your computer and use it in GitHub Desktop.
Save silv3rm00n/1523838 to your computer and use it in GitHub Desktop.
#include<stdio.h>
class A
{
public:
void trial();
void log(int a)
{
printf("%d" , a);
}
};
class B
{
public:
//void (*logger)(int);
void (A::*logger)(int);
//void set_handler(void (*functocall)(int))
void set_handler(void (A::*functocall)(int))
{
logger = functocall;
}
void test()
{
(*((A*)this).*logger)(5);
}
};
void A::trial()
{
B bb;
bb.set_handler(&A::log);
bb.test();
}
int main()
{
A aa;
aa.trial();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment