-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (40 loc) · 1.81 KB
/
Copy pathmain.cpp
File metadata and controls
50 lines (40 loc) · 1.81 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
42
43
44
45
46
47
48
49
50
#include "Animal.hpp"
#include "Cat.hpp"
#include "Dog.hpp"
#include <iostream>
int main()
{
// Test de classe abstraite : decommenter pour verifier qu'Animal ne peut pas etre instanciee
// Animal animal;
// error: cannot declare variable ‘animal’ to be of abstract type ‘Animal’
std::cout << "\nCreation (animal->brain->dog/cat) :" << std::endl;
const Animal* dog = new Dog();
const Animal* cat = new Cat();
std::cout << "\nTypes des animaux (ex00) :" << std::endl;
std::cout << "Dog type : " << dog->getType() << std::endl;
std::cout << "Cat type : " << cat->getType() << std::endl;
std::cout << "\nSons des animaux (polymorphisme fonctionnel) (ex00) :" << std::endl;
std::cout << "Cat sound : ";
cat->makeSound();
std::cout << "Dog sound : ";
dog->makeSound();
std::cout << "\nDestruction des animaux (brain->dog/cat->animal) :" << std::endl;
delete dog;
delete cat;
std::cout << "\nCopie profonde (ex01) :" << std::endl;
std::cout << "Creation du original chien :" << std::endl;
Dog original;
original.getBrain()->setIdea(0, "Original idea");
std::cout << "Original chien idea : " << original.getBrain()->getIdea(0) << std::endl;
std::cout << "\nCreation du copy-chien :" << std::endl;
Dog copy = original;
std::cout << "Apres copie -> Copy-chien idea : " << copy.getBrain()->getIdea(0) << std::endl;
copy.getBrain()->setIdea(0, "Copy idea");
std::cout << "\nApres modification des idees du copy-chien :" << std::endl;
std::cout << "Original chien : " << original.getBrain()->getIdea(0) << std::endl;
std::cout << "Copy-chien : " << copy.getBrain()->getIdea(0) << std::endl;
std::cout << "\nOriginal chien brain address : " << original.getBrain() << std::endl;
std::cout << "Copy-chien brain address : " << copy.getBrain() << std::endl;
std::cout << "\nDestruction :" << std::endl;
return 0;
}