Answer the question
In order to leave comments, you need to log in
C++. Inheritance relations in OOP. What corresponds to what?
I am reading "The C++ Programming Language. Lectures and Exercises." — Prata.
It mentions (as far as I could see) five inheritance relationships:
Answer the question
In order to leave comments, you need to log in
1. is-a - inheritance
class Car : public Vehicle {
// автомобиль является транспортом
};
class Car {
Engine v8; // автомобиль имеет (содержит) двигатель
};
class Driver {
Car* myCar; // водитель использует автомобиль
};
class Square : public Figure;
class Rectangle : public Figure;
// квадрат и прямоугольник похожи по свойствам, но это разные фигуры
class Engine { // абстракция
public:
virtual void start() = 0;
protected:
float power;
};
class V8 : public Engine { // реализация
virtual void start() {
// wroom wroom
}
};
// Двигатель ДВС реализован как 8-ми цилиндровый двигатель V-конфигурации
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question