Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <set>
- #include <string>
- #include <iostream>
- using namespace std;
- // Человек
- class Person {
- public:
- Person() {
- cout << "Конструткор по умолчанию класса Person" << endl;
- };
- Person(string name) {
- name_ = name;
- cout << "Параметризованный конструткор класса Person" << endl;
- };
- Person(string name, int age) {
- name_ = name;
- age_ = age;
- cout << "другой параметризованный конструткор класса Person" << endl;
- };
- string GetName() const {
- return name_;
- }
- int GetAge() const {
- return age_;
- }
- string GetGender() const {
- return gender_;
- }
- ~Person() {
- cout << "Деструктор класса Person" << endl;
- };
- private:
- string name_ = "Иван";
- string gender_ = "М";
- int age_ = 33;
- };
- // Рабочий. Владеет несколькими специальностями
- class Worker : public Person {
- public:
- Worker() {
- cout << "Вызываем конструктор по умолчанию" << endl;
- };
- /* Worker() : Person("Гена") {
- cout << "Вызываем параметризованный" << endl;
- };
- Worker() : Person("Гена", 33) {
- cout << "Вызываем другой параметризованный конструктор" << endl;
- };*/
- Worker(string name, int age) :Person(name, age) {
- cout << "Вызываем другой параметризованный конструктор" << endl;
- };
- void AddSpeciality(string speciality) {
- specialties_.insert(speciality);
- }
- bool HasSpeciality(string speciality) const {
- return specialties_.count(speciality);
- }
- ~Worker() {
- cout << "Деструктор класса Worker" << endl;
- };
- private:
- set<string> specialties_;
- };
- int main() {
- setlocale(LC_ALL, "ru");
- Worker wr;
- cout << wr.GetName() << endl;
- //Worker wr2("Гена", 33);
- //cout << wr2.GetName() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement