fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class mobject
  5. {
  6. public:
  7. mobject(const mobject& ob){ cout << "mobject overridden-copy-constructor\n"; }
  8. mobject(){ cout << "mobject ctor\n"; }
  9. ~mobject(){ cout << "mobject dtor\n"; }
  10. };
  11.  
  12. mobject giveme()
  13. {
  14. cout << "1. In Function: "<<__func__<<endl;
  15. return mobject();
  16. }
  17. void func2(const mobject& p)
  18. {
  19. cout << "2. In Function: "<<__func__<<endl;
  20. mobject g = p;
  21. cout << "3. In Function: "<<__func__<<endl;
  22. }
  23. void func1(const mobject& p)
  24. {
  25. cout << "4. In Function: "<<__func__<<endl;
  26. func2(p);
  27. cout << "5. In Function: "<<__func__<<endl;
  28. }
  29. int main()
  30. {
  31. cout << "6. In Function: "<<__func__<<endl;
  32. func1(giveme());
  33. cout << "7. In Function: "<<__func__<<endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 4344KB
stdin
Standard input is empty
stdout
6. In Function: main
1. In Function: giveme
mobject ctor
4. In Function: func1
2. In Function: func2
mobject overridden-copy-constructor
3. In Function: func2
mobject dtor
5. In Function: func1
mobject dtor
7. In Function: main