Untitled
unknown
c_cpp
3 years ago
789 B
4
Indexable
//файл main.cpp #include <iostream> #include "Circle.h" #include "Round.h" #include "Cylinder.h" #include "Shape.h" using namespace std; //вказівники на віртуальний метод void GetLength(Shape* shape) { cout << shape->CircleLength() << endl; } void GetArea(Shape* shape) { cout << shape->Area() << endl; } void GetVolume(Shape* shape) { cout << shape->Volume() << endl; } int main() { //масив вказівників на абстрактний клас Shape* p[3] = { new Circle(3), new Round(2), new Cylinder(5, 4) }; //пізнє зв'язування for (int i = 0; i < 1; ++i) { GetLength(p[0]); GetArea(p[1]); GetVolume(p[2]); } return 0; }
Editor is loading...