#include #include using namespace std; class Human { protected: string name; int age; public: Human(string n, int a) : name(n), age(a) { cout << "ctor Human" << endl; } string getName() const { return name; } int gatAge() const { return age; } }; class Employee : public Human { friend void applyTax(Employee &employee); private: double wage; public: Employee(string n, int a, double w) : wage(w), Human(n, a) { cout << "ctor Employee" << endl; } double getWage() const { return wage; } void print() const { cout << name << " " << age << " " << wage << endl; } }; // Дружественная функция для доступа к приватным членам void applyTax(Employee &employee) { employee.wage *= 0.87; } // Приватный тип наследования. Можно записать как: class pEmployee : private Human class pEmployee : private Human { private: double wage; public: pEmployee(string n, int a, double w) : wage(w), Human(n, a) { cout << "ctor Employee" << endl; } }; // --------------------------------------------------------------------------------- // class Shape { public: virtual void show() = 0; }; class Circle : public Shape { public: void show() { cout << "Circle" << endl; } }; class Triangle : Shape { public: void show() { cout << "Triangle" << endl; } }; // --------------------------------------------------------------------------------- // class D { public: D() {cout << "D";} virtual ~D() {cout << "~D";} }; class A : public D { public: A() {cout << "A";} ~A() {cout << "~A";} }; class C : public D { public: C() {cout << "C";} virtual ~C() {cout << "~C";} }; class B : public A,C { public: B() {cout << "B";} ~B() {cout << "~B";} }; // --------------------------------------------------------------------------------- // enum sex_t {male, female}; class Person { private: string name; int age; sex_t sex; float weight; public: Person(string n, int a, sex_t s, float w) : name(n), age(a), sex(s), weight(w) {} void setName(string n) { name = n; } }; class Student : public Person { }; int main() { Employee worker("Ivan", 20, 100000); applyTax(worker); worker.print(); // pEmployee worker2("Sergey", 20, 120000); // worker2.print(); Shape* shape1; shape1 = new Circle(); shape1->show(); A* b = new B(); delete b; return 0; }