fork download
  1. #include <iostream>
  2.  
  3. extern "C"
  4. {
  5. typedef void call_back( const void*, int ) ;
  6.  
  7. void c_fun( call_back function, const void* arg1 )
  8. {
  9. for( int i = 0 ; i < 4 ; ++i ) function( arg1, i ) ;
  10. }
  11. }
  12.  
  13. struct A
  14. {
  15. void foo( int value ) const { std::cout << "void A::foo(int) const - value == " << value << '\n' ; }
  16. };
  17.  
  18. extern "C"
  19. {
  20. void call_A_foo( const void* This, int v ) { static_cast< const A* >( This )->foo(v) ; }
  21. }
  22.  
  23. int main()
  24. {
  25. A a ;
  26. c_fun( call_A_foo, &a ) ;
  27. }
  28.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
void A::foo(int) const - value == 0
void A::foo(int) const - value == 1
void A::foo(int) const - value == 2
void A::foo(int) const - value == 3