fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. int n;
  5. A(int i): n(i+1) {
  6. std::cout << "value init" << std::endl;
  7. }
  8. A(const A& rhs): n(rhs.n) {
  9. std::cout << "const copy init" << std::endl;
  10. }
  11. A(A& rhs): n(rhs.n) {
  12. std::cout << "copy init" << std::endl;
  13. }
  14. operator int() const { return n; }
  15. };
  16.  
  17. int main()
  18. {
  19. A x(0);
  20. A y=x;
  21. A z(x);
  22. std::cout << x.n << std::endl;
  23. std::cout << y.n << std::endl;
  24. std::cout << z.n << std::endl;
  25. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
value init
copy init
copy init
1
1
1