Advertisement
josdas

Untitled

Mar 30th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1.  
  2. class Test {
  3. private:
  4.     int g;
  5. public:
  6.     Test() : g(0) {
  7.         cout << "Default constructor\n";
  8.     }
  9.  
  10.     Test(int x) : g(x) {
  11.         cout << "Init int\n";
  12.     }
  13.  
  14.     Test(const Test& t) : g(t.g) {
  15.         cout << "Init test\n";
  16.     }
  17.    
  18.     Test(Test&& t) : g(t.g) {
  19.         cout << "Init rvalue\n";
  20.     }
  21.  
  22.     Test& operator=(const Test& t) {
  23.         cout << "Copy test\n";
  24.         g = t.g;
  25.         return *this;
  26.     }
  27.  
  28.     Test operator+(const Test& t) const {
  29.         cout << "Opeartor add\n";
  30.         return Test(g + t.g);
  31.     }
  32.  
  33.     ~Test() {
  34.         cout << "Destroy\n";
  35.     }
  36. };
  37.  
  38. Test foo(Test&& A) {
  39.     cout << "It is foo(Test &&)\n";
  40.     return *(new Test(-1));
  41. }
  42.  
  43. Test& foo(const Test& A) {
  44.     cout << "It is foo(const Test &)\n";
  45.     return *(new Test(-5));
  46. }
  47.  
  48. void bar() {
  49.     cout << "It is bar()\n";
  50.     foo(Test(5));
  51.     foo(Test(2) + Test(6));
  52.     Test g = 7;
  53.     foo(g + foo(g));
  54. }
  55.  
  56. int main() {
  57.     bar();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement