Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. class B {
  2. public:
  3.     int x;
  4.     B(int z=1): x(z) {}
  5. };
  6. class D: public B {
  7. public:
  8.     int y;
  9.     D(int z=5): B(z-2), y(z) {}
  10. };
  11.  
  12. void fun(B* a, int size) {
  13.     for(int i=0; i<size; ++i) cout << (*(a+i)).x << " ";
  14. }
  15.  
  16. int main() {
  17.     fun(new D[4],4); cout << "**1\n";
  18.     B* b = new D[4]; fun(b,4); cout << "**2\n";
  19.     b[0] = D(6); b[1] = D(9); fun(b,4); cout << "**3\n";
  20.     b = new B[4]; b[0] = D(6); b[1] = D(9);
  21.     fun(b,4); cout << "**4\n";
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement