Advertisement
andybuckley

C++11 __func__

Jun 13th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct Foo {
  6.   Foo() : name(__func__) {  }
  7.   virtual string str() { return name; }
  8.   string name;
  9. };
  10.  
  11. struct Bar : Foo {
  12.   Bar() : name(__func__) {  }
  13.   virtual string str() { return Foo::str() + "->" + name; }
  14.   string name;
  15. };
  16.  
  17. struct Baz : Bar {
  18.   Baz() : name(__func__) {  }
  19.   virtual string str() { return Bar::str() + "->" + name; }
  20.   string name;
  21. };
  22.  
  23.  
  24. int main() {
  25.   Foo f;
  26.   cout << f.str() << endl;
  27.  
  28.   Bar b;
  29.   cout << b.str() << endl;
  30.  
  31.   Baz z;
  32.   cout << z.str() << endl;
  33.  
  34.   return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement