fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. struct foo
  5. {
  6. int i;
  7. foo(int i): i(i) { cout << "int constructor, i = " << i << '\n'; }
  8. foo(const foo&f): i(f.i) {cout << "Copy constructor, i = " << i << '\n';}
  9. void operator=(const foo&f) {i = f.i; cout << "Assignment. i = " << i << '\n'; }
  10. ~foo() {cout << "Destructor. i = " << i << '\n'; }
  11. };
  12.  
  13.  
  14. int main()
  15. {
  16. foo a(5);
  17. foo b= 6;
  18. foo c = foo(7);
  19. }
  20.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
int constructor, i = 5
int constructor, i = 6
int constructor, i = 7
Destructor. i = 7
Destructor. i = 6
Destructor. i = 5