d04 ex01 ok change affichage + delete brain + constructors with default arguments

This commit is contained in:
hugogogo
2022-02-26 19:20:49 +01:00
parent 12f4c72e77
commit ed2bbc7fd2
8 changed files with 116 additions and 29 deletions

View File

@@ -6,14 +6,28 @@
* CONSTRUCTORS
*********************************************/
Dog::Dog( Brain *brain ) {
Dog::Dog() {
std::cout << COPLIEN_COLOR "Dog constructor" RESET "\n";
type = "dog";
_brain = brain;
_brain = new Brain();
return;
}
Dog::Dog( Brain *brain ) {
std::cout << COPLIEN_COLOR "Dog constructor" RESET "\n";
type = "dog";
_brain = new Brain();
*_brain = *brain;
return;
}
/*
error: base class class Animal should be explicitly initialized in the copy constructor [-Werror=extra]
Dog::Dog( Dog const & src ) {
^~~
answer : https://stackoverflow.com/questions/43612772/base-class-class-a-should-be-explicitly-initialized-in-the-copy-constructor
*/
Dog::Dog( Dog const & src ) : Animal() {
std::cout << COPLIEN_COLOR "Dog copy constructor" RESET "\n";
*this = src;
return;
@@ -25,6 +39,7 @@ Dog::Dog( Dog const & src ) {
Dog::~Dog() {
std::cout << COPLIEN_COLOR "Dog destructor" RESET "\n";
delete _brain;
return;
}
@@ -34,7 +49,9 @@ Dog::~Dog() {
Dog & Dog::operator=( Dog const & rhs ) {
Animal::operator=(rhs);
_brain = rhs._brain;
_brain = new Brain();
if (this != &rhs)
_brain = rhs._brain;
return *this;
}