Advertisement
iskhakovt

virtual

Sep 6th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. struct Object
  4. {
  5.     virtual int get_size() = 0;
  6. };
  7.  
  8. struct Zero : Object
  9. {
  10.     int get_size() {return 0;}
  11. };
  12.  
  13. struct One : Object
  14. {
  15.     int get_size() {return 1;}
  16. };
  17.  
  18. struct Two : Object
  19. {
  20.     int get_size() {return 2;}
  21. };
  22.  
  23. int main()
  24. {
  25.     Object *Mass[3];
  26.  
  27.     /* Заполним массив */
  28.     Mass[0] = new Zero;
  29.     Mass[1] = new One;
  30.     Mass[2] = new Two;
  31.  
  32.     for (unsigned int i = 0; i < 3; i++)
  33.         printf("%d\n", Mass[i]->get_size());
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement