@related: address
#include <stdio.h> #include <stdlib.h> #define LOGF(...) \ printf( __VA_ARGS__ ) #define LOG(...) \ LOGF("%s:%d: log: '%s'\n" ,__FILE__ , __LINE__, __PRETTY_FUNCTION__) void funct() { LOG(); } void functArg( void (*f)() ) { LOG(); (*f)(); } struct Functor; struct Functor { void operator()() { LOG(); } static void functStatic() { LOG(); } static struct Functor* self; static void wrap() { LOG(); (*self)(); } }; struct Functor* Functor::self = 0; //TODO /// executable entry int main(int argc, char* argv[]) { LOG(); if ( true ) { functArg(funct); Functor my_functor; my_functor(); functArg(my_functor.functStatic ); //functArg(my_functor); // error: cannot convert // 'Functor' to 'void (*)()' // for argument '1' to 'void functArg(void (*)())' my_functor.self = &my_functor; functArg(my_functor.wrap ); } return EXIT_SUCCESS; } /* ### LOG ### make -k run g++ main.cpp -o main ./main main.cpp:57: log: 'int main(int, char**)' main.cpp:22: log: 'void functArg(void (*)())' main.cpp:16: log: 'void funct()' main.cpp:34: log: 'void Functor::operator()()' main.cpp:22: log: 'void functArg(void (*)())' main.cpp:39: log: 'static void Functor::functStatic()' main.cpp:22: log: 'void functArg(void (*)())' main.cpp:45: log: 'static void Functor::wrap()' main.cpp:34: log: 'void Functor::operator()()' */