Created
December 27, 2011 14:33
-
-
Save silv3rm00n/1523823 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() | |
{ | |
(*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