SHARE
TWEET

Untitled

a guest Jan 20th, 2013 283 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5.     A()
  6.     {
  7.         std::cout << "A()" << std::endl;
  8.     }
  9.  
  10.     A(const A&)
  11.     {
  12.         std::cout << "A(const A&)" << std::endl;
  13.     }
  14.  
  15.     ~A()
  16.     {
  17.         std::cout << "~A()" << std::endl;
  18.     }
  19. };
  20.  
  21. A func1()
  22. {
  23.     A a;
  24.     return a;
  25. }
  26.  
  27. A func2()
  28. {
  29.     return A();
  30. }
  31.  
  32. int main()
  33. {
  34.     std::cout << "func1" << std::endl;
  35.     A a1 = func1();
  36.     std::cout << "func2" << std::endl;
  37.     A a2 = func2();
  38.     std::cout << "finish" << std::endl;
  39.     return 0;
  40. }
  41.  
  42. /* output:
  43.  
  44. func1
  45. A()
  46. A(const A&)
  47. ~A()
  48. A(const A&)
  49. ~A()
  50. func2
  51. A()
  52. A(const A&)
  53. ~A()
  54. A(const A&)
  55. ~A()
  56. finish
  57. ~A()
  58. ~A()
  59.  
  60. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top