fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. public:
  8. A(){cout << "i get this default constructor when I create a B" << endl;}
  9. A(int i){cout << "this is the constructor i want when I create a B" << endl;}
  10. };
  11.  
  12. class B
  13. {
  14. A a;
  15.  
  16. public: B() : a(5) {}
  17. };
  18.  
  19. int main()
  20. {
  21. B *ptr = new B;
  22. return 0;
  23. }
Success #stdin #stdout 0.02s 2856KB
stdin
Standard input is empty
stdout
this is the constructor i want when I create a B