-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (31 loc) · 1.02 KB
/
Copy pathmain.cpp
File metadata and controls
41 lines (31 loc) · 1.02 KB
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
#include <iostream>
#include <vector>
#include "PirelliFerrari.h"
int main() {
PirelliFerrari machine("Pirelli", "Ferrari");
FerrariPrototype prototype("BMW");
std::vector<Prototype*> machines {&machine, &prototype};
std::vector<Prototype*> clones;
clones.reserve(machines.size());
for (Prototype* vehicle : machines) {
clones.push_back(vehicle->clone());
}
for (Prototype* vehicle : clones) {
auto * actual_prototype = dynamic_cast<FerrariPrototype*>(vehicle);
if (actual_prototype == nullptr) {
std::cout << "Could not casted to FerrariPrototype" << std::endl;
} else {
std::cout << actual_prototype->GetEngineName() << " is cloned" << std::endl;
}
auto * pirelli = dynamic_cast<PirelliFerrari*>(vehicle);
if (pirelli == nullptr) {
std::cout << "Could not casted to PirelliFerrari" << std::endl;
} else {
std::cout << pirelli->GetShassiName() << " shassi is cloned" << std::endl;
}
}
for (Prototype * vehicle: clones){
delete vehicle;
}
return 0;
}