Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Shape {
- public:
- virtual void draw() const = 0;
- virtual ~Shape() {};
- };
- class Circle : public Shape {
- public:
- Circle(int p, int rr) : x{p}, r{rr} {}
- void draw() const { std::cout << "In Circle::draw()" << std::endl; }
- private:
- int x;
- int r;
- };
- class Smiley : public Circle {
- public:
- Smiley(int p, int r): Circle{p,r}, mouth(nullptr) {}
- ~Smiley() { delete mouth; }
- void draw() const { std::cout << "In Smiley::draw()" << std::endl; }
- private:
- Shape* mouth;
- };
- int
- main(int argc, char *argv[])
- {
- Circle *smiley;
- smiley = new Smiley(3, 4);
- smiley->draw();
- Circle *circle;
- circle = new Circle(3, 4);
- circle->draw();
- return 0;
- }
- In Smiley::draw()
- In Circle::draw()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement