-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinheritanceAbstractBase.cpp
64 lines (42 loc) · 1015 Bytes
/
inheritanceAbstractBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string>
class Abstract{
public:
virtual ~Abstract() = 0;
};
Abstract::~Abstract() = default;
class Concret: public Abstract{};
class HumanBeing{
public:
HumanBeing(const std::string& n): name(n){
std::cout << name << " created." << '\n';
}
virtual std::string getSex() const= 0;
private:
std::string name;
};
class Man: public HumanBeing{
public:
Man(const std::string& n): HumanBeing(n){}
std::string getSex() const override {
return "male";
}
};
class Woman: public HumanBeing{
public:
Woman(const std::string& n): HumanBeing(n){}
std::string getSex() const override {
return "female";
}
};
int main(){
std::cout << '\n';
// Abstract abstract; // ERROR
Concret concret;
HumanBeing humanBeing("grimm"); // ERROR
Man schmidt("Schmidt");
Woman huber("Huber");
std::cout << "schmidt.getSex(): " << schmidt.getSex() << '\n';
std::cout << "huber.getSex(): " << huber.getSex() << '\n';
std::cout << '\n';
}