fork download
  1. #include <iostream>
  2.  
  3. class Inner
  4. {
  5. public:
  6. int x;
  7. Inner()
  8. {
  9. std::cout << "Inner (no params)" << std::endl;
  10. }
  11. Inner(int _x) : x(_x)
  12. {
  13. std::cout << "inner (param "<<x <<" )"<<std::endl;
  14. }
  15. };
  16. class Outer
  17. {
  18. public:
  19. Inner i;
  20. Outer(Inner _i)
  21. {
  22. i = _i;
  23. std::cout << "Outer" << std::endl;
  24. }
  25. };
  26. class CorrectOuter
  27. {
  28. public:
  29. Inner i;
  30. CorrectOuter(Inner _i) : i (_i)
  31. {
  32. std::cout << "CorrectOuter" << std::endl; }
  33. };
  34. int main()
  35. {
  36. Inner i(3);
  37. Outer o(i);
  38. CorrectOuter co(i);
  39. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
inner (param 3 )
Inner (no params)
Outer
CorrectOuter