@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()()'

*/

6.asset.soup.io_asset_1972_5110_79e2.jpeg

ptr.txt · Last modified: 2022/04/16 12:23 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki