d04 ex02 ok, presque rien a changer ou je me trompe ?

This commit is contained in:
hugogogo
2022-02-26 22:12:55 +01:00
parent ed2bbc7fd2
commit c056db80b7
27 changed files with 597 additions and 68 deletions

65
d04/ex01/srcs/Dog.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "Dog.hpp"
#define COPLIEN_COLOR B_CYAN
/*********************************************
* CONSTRUCTORS
*********************************************/
Dog::Dog() {
std::cout << COPLIEN_COLOR "Dog constructor" RESET "\n";
type = "dog";
_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;
}
/*********************************************
* DESTRUCTORS
*********************************************/
Dog::~Dog() {
std::cout << COPLIEN_COLOR "Dog destructor" RESET "\n";
delete _brain;
return;
}
/*********************************************
* OPERATORS
*********************************************/
Dog & Dog::operator=( Dog const & rhs ) {
Animal::operator=(rhs);
_brain = new Brain();
if (this != &rhs)
_brain = rhs._brain;
return *this;
}
/*********************************************
* PUBLIC MEMBER FUNCTIONS
*********************************************/
void Dog::makeSound() const {
std::cout << "*woof*\n";
}