fork(1) download
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. public:
  6. A() { std::cout << "regular constructor\n"; }
  7. ~A() { std::cout << "destructor\n"; }
  8. A(A const&) { std::cout << "copy constructor\n"; }
  9. };
  10.  
  11. class B
  12. {
  13. public:
  14. B() : a_(A()) {}
  15. B(A const& a) : a_(a) {}
  16. private:
  17. A a_;
  18. };
  19.  
  20. int main()
  21. {
  22. B b;
  23. // "-----------------------------"
  24. A a;
  25. B b1(a);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
regular constructor
regular constructor
copy constructor
destructor
destructor
destructor