Artem78

Log class name

Sep 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. #define LOG(msg) log(__CLASS__, msg);
  7.  
  8. void log(const char* cls, string str)
  9. {
  10.     cout << "[" << cls << "] " << str << endl;
  11. }
  12.  
  13.  
  14. class MyClass1
  15. {
  16. public:
  17.     void foo()
  18.         {
  19.             LOG("the message");
  20.         }
  21. };
  22.  
  23. class MyClass2
  24. {
  25. public:
  26.     void foo()
  27.         {
  28.             LOG("another one message");
  29.         }
  30. };
  31.  
  32.  
  33.  
  34. int main()
  35. {
  36.     MyClass1 obj1;
  37.     MyClass2 obj2;
  38.    
  39.     obj1.foo(); // [MyClass1] the message
  40.     obj2.foo(); // [MyClass2] another one message
  41.  
  42.     system("pause");
  43.     return 0;
  44. }
Add Comment
Please, Sign In to add comment