diff --git a/d04/ex02/Makefile b/d04/ex02/Makefile index 41d7f5a..f10adf4 100644 --- a/d04/ex02/Makefile +++ b/d04/ex02/Makefile @@ -13,7 +13,7 @@ ifeq "$(TYPE)" "c" CC = c EXT = c else ifeq "$(TYPE)" "cpp" - CC = clang++ + CC = c++ EXT = cpp endif diff --git a/d04/ex02/headers/Animal.hpp b/d04/ex02/headers/Animal.hpp index 8378a82..673dd6e 100644 --- a/d04/ex02/headers/Animal.hpp +++ b/d04/ex02/headers/Animal.hpp @@ -17,7 +17,7 @@ public: virtual void makeSound() const = 0; std::string getType() const; - virtual Brain * getBrain() const = 0; +// virtual Brain * getBrain() const = 0; protected: std::string type; diff --git a/d04/ex02/headers/Cat.hpp b/d04/ex02/headers/Cat.hpp index 1c69329..f4246c3 100644 --- a/d04/ex02/headers/Cat.hpp +++ b/d04/ex02/headers/Cat.hpp @@ -19,7 +19,7 @@ public: Cat( Cat const & src ); ~Cat(); Cat & operator=( Cat const & rhs ); - Cat & operator=( Animal const & rhs ); +// Cat & operator=( Animal const & rhs ); void makeSound() const; diff --git a/d04/ex02/headers/Dog.hpp b/d04/ex02/headers/Dog.hpp index 2fdc58d..b777369 100644 --- a/d04/ex02/headers/Dog.hpp +++ b/d04/ex02/headers/Dog.hpp @@ -17,7 +17,7 @@ public: Dog( Dog const & src ); ~Dog(); Dog & operator=( Dog const & rhs ); - Dog & operator=( Animal const & rhs ); +// Dog & operator=( Animal const & rhs ); void makeSound() const; Brain * getBrain() const; diff --git a/d04/ex02/main.cpp b/d04/ex02/main.cpp index e83576d..75d5414 100644 --- a/d04/ex02/main.cpp +++ b/d04/ex02/main.cpp @@ -18,25 +18,25 @@ int main() { std::cout << std::endl; std::cout << B_BLUE "cat i : " RESET; - i->getBrain()->printIdea(0); + dynamic_cast(i)->getBrain()->printIdea(0); std::cout << B_BLUE "cat j : " RESET; - j->getBrain()->printIdea(0); + dynamic_cast(j)->getBrain()->printIdea(0); std::cout << "\n" B_BLUE "*i = *j" RESET "\n"; - *i = *j; + *(dynamic_cast(i)) = *(dynamic_cast(j)); std::cout << B_BLUE "cat i : " RESET; - i->getBrain()->printIdea(0); + dynamic_cast(i)->getBrain()->printIdea(0); std::cout << B_BLUE "cat j : " RESET; - j->getBrain()->printIdea(0); + dynamic_cast(j)->getBrain()->printIdea(0); std::cout << "\n" B_BLUE "j->getBrain->putIdea(\"I am not a cat\")" RESET "\n"; - j->getBrain()->putIdea(0, "I am not a cat");; + dynamic_cast(j)->getBrain()->putIdea(0, "I am not a cat");; std::cout << B_BLUE "cat i : " RESET; - i->getBrain()->printIdea(0); + dynamic_cast(i)->getBrain()->printIdea(0); std::cout << B_BLUE "cat j : " RESET; - j->getBrain()->printIdea(0); + dynamic_cast(j)->getBrain()->printIdea(0); std::cout << std::endl; std::cout << B_BLUE "delete i" RESET "\n"; diff --git a/d04/ex02/pure b/d04/ex02/pure new file mode 100755 index 0000000..964e580 Binary files /dev/null and b/d04/ex02/pure differ diff --git a/d04/ex02/srcs/Cat.cpp b/d04/ex02/srcs/Cat.cpp index 621d138..16d32f6 100644 --- a/d04/ex02/srcs/Cat.cpp +++ b/d04/ex02/srcs/Cat.cpp @@ -67,6 +67,7 @@ Cat & Cat::operator=( Cat const & rhs ) { } // need of a second overload in case "Animal cat" = "Animal cat"; // https://stackoverflow.com/questions/68248198/why-my-virtual-assignment-operator-not-doing-as-intended +/* Cat & Cat::operator=( Animal const & rhs ) { Animal::operator=(rhs); std::cout << COPLIEN_COLOR "Cat (Animal) assignator" RESET "\n"; @@ -74,6 +75,7 @@ Cat & Cat::operator=( Animal const & rhs ) { *_brain = *(rhs.getBrain()); return *this; } +*/ /********************************************* * PUBLIC MEMBER FUNCTIONS diff --git a/d04/ex02/srcs/Dog.cpp b/d04/ex02/srcs/Dog.cpp index cacfa69..9686c7f 100644 --- a/d04/ex02/srcs/Dog.cpp +++ b/d04/ex02/srcs/Dog.cpp @@ -56,6 +56,7 @@ Dog & Dog::operator=( Dog const & rhs ) { } // need of a second overload in case "Animal cat" = "Animal cat"; // https://stackoverflow.com/questions/68248198/why-my-virtual-assignment-operator-not-doing-as-intended +/* Dog & Dog::operator=( Animal const & rhs ) { Animal::operator=(rhs); std::cout << COPLIEN_COLOR "Cat (Animal) assignator" RESET "\n"; @@ -63,6 +64,7 @@ Dog & Dog::operator=( Animal const & rhs ) { *_brain = *(rhs.getBrain()); return *this; } +*/ /********************************************* * PUBLIC MEMBER FUNCTIONS