fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A {
  5. int a;
  6. A(int x);
  7. void print();
  8. };
  9.  
  10. struct B : A {
  11. int b;
  12. B(int x, int y);
  13. void print();
  14. };
  15.  
  16. struct C : B {
  17. int c;
  18. C(int x, int y, int z);
  19. void print();
  20. };
  21.  
  22. A::A(int x):a(x) {
  23. }
  24.  
  25. void A::print() {
  26. cout << a << endl;
  27. }
  28.  
  29. B::B(int x, int y):A(x),b(y) {
  30. }
  31.  
  32. void B::print() {
  33. A::print();
  34. cout << b << endl;
  35. }
  36.  
  37. C::C(int x, int y, int z):B(x,y),c(z) {
  38. }
  39.  
  40. void C::print() {
  41. B::print();
  42. cout << c << endl;
  43. }
  44.  
  45. int main() {
  46. C c = {1,2,3};
  47. c.print();
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
1
2
3