fork(2) download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct foo
  5. {
  6. int i;
  7. foo():i()
  8. {
  9. cout<<"foo c'tor"<<endl;
  10. }
  11. ~foo()
  12. {
  13. cout<<"foo d'tor"<<endl;
  14. }
  15. };
  16.  
  17. struct bar
  18. {
  19. const foo &ref;
  20. bar():ref(foo())
  21. {
  22. cout<<"bar c'tor"<<endl<<"ref.i="<<ref.i<<endl;
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. bar obj;
  29. }
  30.  
  31.  
Success #stdin #stdout 0s 2724KB
stdin
Standard input is empty
stdout
foo c'tor
foo d'tor
bar c'tor
ref.i=0