Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
2 files changed, 13 insertions, 1 deletions
-rw-r--r--Sem. 12/Example_polymorphism/Shape.cpp4
-rw-r--r--Sem. 12/README.MD10
diff --git a/Sem. 12/Example_polymorphism/Shape.cpp b/Sem. 12/Example_polymorphism/Shape.cpp
index 27bb9e9..468c621 100644
--- a/Sem. 12/Example_polymorphism/Shape.cpp
+++ b/Sem. 12/Example_polymorphism/Shape.cpp
@@ -8,9 +8,11 @@ Shape::Shape(size_t pointsCount) : pointsCount(pointsCount)
void Shape::copyFrom(const Shape& other)
{
points = new point[other.pointsCount];
-
+
for (int i = 0; i < other.pointsCount; i++)
points[i] = other.points[i];
+
+ pointsCount = other.pointsCount;
}
void Shape::free()
{
diff --git a/Sem. 12/README.MD b/Sem. 12/README.MD
index 4e3eab6..95fd3d1 100644
--- a/Sem. 12/README.MD
+++ b/Sem. 12/README.MD
@@ -55,14 +55,24 @@ struct B : public A
}
};
+struct C : public A
+{
+ void f() const
+ {
+ std::cout << "C::f()" << std::endl;
+ }
+};
+
int main()
{
A* ptrs[2];
ptrs[0] = new A();
ptrs[1] = new B();
+ ptrs[2] = new C();
ptrs[0]->f(); // A::f()
ptrs[1]->f(); // B::f()
+ ptrs[2]->f(); // C::f()
}
```
#### Полиморфизъм