fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct A
  6. {
  7. int x;
  8. A(int x) : x(x) {}
  9. virtual ~A() {}
  10. };
  11.  
  12. struct B : A
  13. {
  14. B() : A(7) {}
  15. };
  16.  
  17. int main()
  18. {
  19. A *a = new B[4];
  20.  
  21. for (size_t q=0; q<4; ++q)
  22. cout << q << ": " << a[q].x << endl;
  23.  
  24. delete [] a;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
0: 7
1: 7
2: 7
3: 7