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,15 +6,33 @@
* CONSTRUCTORS
*********************************************/
Cat::Cat( Brain * brain ) {
std::cout << COPLIEN_COLOR "Cat constructor" RESET "\n";
/*
* default arguments in default constructor : https://stackoverflow.com/questions/187640/default-parameters-with-c-constructors
* in this cas it doesn't work i think, since both constructors don't act exactly the same
*/
Cat::Cat() {
std::cout << COPLIEN_COLOR "Cat default constructor" RESET "\n";
type = "cat";
_brain = brain;
_brain = new Brain();
return;
}
Cat::Cat( Brain * brain ) {
std::cout << COPLIEN_COLOR "Cat parameters constructor" RESET "\n";
type = "cat";
_brain = new Brain();
*_brain = *brain;
return;
}
Cat::Cat( Cat const & src ) {
/*
* error: base class class Animal should be explicitly initialized in the copy constructor [-Werror=extra]
* Cat::Cat( Cat const & src ) {
* ^~~
* answer : https://stackoverflow.com/questions/43612772/base-class-class-a-should-be-explicitly-initialized-in-the-copy-constructor
*/
Cat::Cat( Cat const & src ) : Animal(src) {
std::cout << COPLIEN_COLOR "Cat copy constructor" RESET "\n";
_brain = new Brain();
*this = src;
return;
}
@@ -25,6 +43,7 @@ Cat::Cat( Cat const & src ) {
Cat::~Cat() {
std::cout << COPLIEN_COLOR "Cat destructor" RESET "\n";
delete _brain;
return;
}