-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (26 loc) · 718 Bytes
/
main.cpp
File metadata and controls
34 lines (26 loc) · 718 Bytes
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
//
// Created by Pavel Akhtyamov on 2019-03-26.
//
#include <memory>
#include <iostream>
#include <Dish.h>
#include <Milk.h>
#include <Breakfast.h>
template <typename T>
std::shared_ptr<DishComponent> CreateDishComponent() {
return std::dynamic_pointer_cast<DishComponent>(std::make_shared<T>());
}
template <typename T>
std::shared_ptr<Dish> CreateDish() {
return std::dynamic_pointer_cast<Dish>(std::make_shared<T>());
}
int main() {
auto ration = std::make_shared<Dish>()->Add(
CreateDish<Breakfast>()
->Add(CreateDishComponent<Milk>())
->Add(CreateDishComponent<Milk>())
)->Add(
CreateDishComponent<Milk>()
);
std::cout << ration->GetCalories() << std::endl;
}