fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. public:
  8. int x;
  9. A(int i)
  10. {
  11.  
  12. x= i;
  13. cout<<"Constructor is Called "<<x<<endl;
  14. }
  15. ~A()
  16. {
  17. cout<<"destructor is Called "<<x<<endl;
  18. }
  19.  
  20. A(const A &a) : x(a.x)
  21. {
  22. cout<<"in copy constructor a.x = "<<a.x<<endl;
  23. cout<<" x = "<<x<<endl;
  24. }
  25. };
  26.  
  27. A fun(int i)
  28. {
  29. cout<<"in Fun"<<endl;
  30. A t(i+1);
  31. return(t);
  32. }
  33.  
  34. int main()
  35. {
  36. A *gg = new A(5);
  37. A t = fun(2);
  38. delete gg;
  39. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Constructor is Called 5
in Fun
Constructor is Called 3
destructor is Called 5
destructor is Called 3