Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Shape {
  4. public:
  5. virtual void draw() const = 0;
  6. virtual ~Shape() {};
  7. };
  8.  
  9. class Circle : public Shape {
  10. public:
  11. Circle(int p, int rr) : x{p}, r{rr} {}
  12. void draw() const { std::cout << "In Circle::draw()" << std::endl; }
  13. private:
  14. int x;
  15. int r;
  16. };
  17.  
  18. class Smiley : public Circle {
  19. public:
  20. Smiley(int p, int r): Circle{p,r}, mouth(nullptr) {}
  21. ~Smiley() { delete mouth; }
  22. void draw() const { std::cout << "In Smiley::draw()" << std::endl; }
  23.  
  24. private:
  25. Shape* mouth;
  26. };
  27.  
  28. int
  29. main(int argc, char *argv[])
  30. {
  31. Circle *smiley;
  32. smiley = new Smiley(3, 4);
  33. smiley->draw();
  34.  
  35. Circle *circle;
  36. circle = new Circle(3, 4);
  37. circle->draw();
  38.  
  39. return 0;
  40. }
  41.  
  42. In Smiley::draw()
  43. In Circle::draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement