ulvis.paste.net

Paste Search Dynamic
Recent pastes
shape
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Shape{
  5.         public: virtual void draw() = 0;
  6. };
  7.  
  8. class Circle: public Shape{
  9.         public: void draw(){
  10.                         cout << "it is Circle" << endl;
  11.                 }
  12. };
  13.  
  14. class Rectangle: public Shape{
  15.         public: void draw(){
  16.                         cout << "it is Rectangle" << endl;
  17.                 }
  18. };
  19.  
  20. class Square: public Rectangle{
  21.         public: void draw(){
  22.                         cout << "it is Square" << endl;
  23.                 }
  24. };
  25.  
  26. int main() {
  27.         // your code goes here
  28.         Square* sq = new Square;
  29.         Rectangle* rect = new Rectangle;
  30.         Shape* ptr_shape;
  31.  
  32.         ptr_shape = sq;
  33.         ptr_shape->draw();
  34.  
  35.         rect = sq;
  36.         rect->draw();
  37.  
  38.         Square sq2;
  39.         Rectangle rect2;
  40.         rect2 = sq2;
  41.         rect2.draw();
  42.  
  43.         return 0;
  44. }
Parsed in 0.006 seconds