fork download
  1. #include <iostream>
  2.  
  3. class Logger
  4. {
  5. public:
  6. void log(std::string entry)
  7. {
  8. std::cout << entry << std::endl;
  9. }
  10. };
  11.  
  12. class A
  13. {
  14. Logger mylog;
  15. public:
  16. void foo()
  17. {
  18. std::cout << "Doing foo" << std::endl;
  19. }
  20.  
  21. Logger& getLogger()
  22. {
  23. return mylog;
  24. }
  25. };
  26.  
  27. #define CALL_FUNC_AND_LOG(obj,func) \
  28.   { obj.getLogger().log("Logging "#func); obj.func(); }
  29.  
  30. int main()
  31. {
  32. A a;
  33. CALL_FUNC_AND_LOG(a,foo);
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
Logging foo
Doing foo