-
Notifications
You must be signed in to change notification settings - Fork 21
/
Main.cpp
37 lines (28 loc) · 860 Bytes
/
Main.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
#include "Animals.hpp"
#include "AnimalFactory.hpp"
#include <iostream>
#include <memory>
#include <string>
int main()
{
// Create factories to use later
auto animalFactory = animalfactory::animalFactory();
auto specialDogFactory = animalfactory::animalFactory("special_dog");
auto mediumFarmFactory = animalfactory::farmFactory(20);
// Create one duck now
auto duck = animalfactory::animalFactory("duck")();
// Create base animal object
auto someAnimal = animalFactory();
// Create and downcast special dog to access derived members.
auto specialDog = std::dynamic_pointer_cast<Dog>(
std::shared_ptr<Animal>(
specialDogFactory()
)
);
// Test downcast
std::cout << std::to_string(specialDog->getExtraInt()) << std::endl;
// Create a farm with 20 animals
auto animals = mediumFarmFactory();
animals[0].doSomething();
return 0;
}