Advertisement
High_Light

sos

Mar 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class A{
  6. public:
  7.     virtual void print(){
  8.         cout << "C" << endl;
  9.     }
  10. };
  11.  
  12. class B : public A {
  13. public:
  14.     void print (){
  15.         cout << "O" << endl;
  16.     }
  17. };
  18.  
  19. class C : public A {
  20. public:
  21.     void print () {
  22.         cout << "A" << endl;
  23.     }
  24. };
  25.  
  26. class D : public A {
  27. public:
  28.     void print () {
  29.         cout << "T" << endl;
  30.     }
  31. };
  32.  
  33. int main()
  34. {
  35.     A**ptr = new A*[10];
  36.     ptr[1] = new A();
  37.     ptr[2] = new B();
  38.     ptr[3] = new A();
  39.     ptr[4] = new C();
  40.     for(int i = 5; i < 7; i++)
  41.         ptr[i] = new D();
  42.     for(int i = 0; i < 10; i++)
  43.         ptr[i] -> print();
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement