Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
644521b3a9
@ -21,6 +21,9 @@ void Circle::draw() {
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y - h), "#",
|
||||
color);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Circle::nonVirtual() {
|
||||
std::cout << "Circle nonVirtual" << std::endl;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ protected:
|
||||
public:
|
||||
explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN);
|
||||
void draw() override;
|
||||
void nonVirtual();
|
||||
};
|
||||
|
||||
#endif //C_C_CIRCLE_H
|
||||
|
@ -20,4 +20,8 @@ void Rectangle::draw() {
|
||||
ansiConsole.printText(position.x + (width / 2), i, "#", color);
|
||||
ansiConsole.printText(position.x - (width / 2), i, "#", color);
|
||||
}
|
||||
}
|
||||
|
||||
void Rectangle::nonVirtual() {
|
||||
std::cout << "Rectangle nonVirtual" << std::endl;
|
||||
}
|
@ -12,6 +12,7 @@ protected:
|
||||
public:
|
||||
explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE);
|
||||
void draw() override;
|
||||
void nonVirtual(void);
|
||||
};
|
||||
|
||||
|
||||
|
@ -6,4 +6,8 @@ Shape::Shape(Position position, Colors color) {
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Shape::~Shape() = default;
|
||||
Shape::~Shape() = default;
|
||||
|
||||
void Shape::nonVirtual() {
|
||||
std::cout << "Shape nonVirtual" << std::endl;
|
||||
}
|
@ -12,6 +12,7 @@ public:
|
||||
Shape(Position position, Colors color);
|
||||
virtual ~Shape();
|
||||
virtual void draw() = 0;
|
||||
void nonVirtual(void);
|
||||
};
|
||||
|
||||
#endif
|
@ -5,6 +5,16 @@
|
||||
#include "Rectangle.h"
|
||||
#include "Scene.h"
|
||||
|
||||
void invokeVirtually(Shape* shape) {
|
||||
if(auto *r = dynamic_cast<Rectangle*>(shape)) {
|
||||
r->nonVirtual();
|
||||
}else if(auto *c = dynamic_cast<Circle*>(shape)) {
|
||||
c->nonVirtual();
|
||||
}else {
|
||||
shape->nonVirtual();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::vector<Shape*> shapes;
|
||||
|
||||
@ -23,12 +33,16 @@ int main(int argc, char **argv) {
|
||||
shapes.push_back(new Point(15, 7, Colors::WHITE));
|
||||
shapes.push_back(new Point(7, 5, Colors::WHITE));
|
||||
|
||||
|
||||
auto *s = new Scene(shapes);
|
||||
s->draw();
|
||||
|
||||
delete s;
|
||||
|
||||
|
||||
invokeVirtually(new Circle(30, 10, 10, Colors::RED));
|
||||
invokeVirtually(new Rectangle(5, 5, 5, 5, Colors::BLUE));
|
||||
invokeVirtually(new Point(5, 5, Colors::YELLOW));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user