diff --git a/cpp05/ex03/Form.hpp b/cpp05/ex03/Form.hpp index c86d973..b1ff555 100644 --- a/cpp05/ex03/Form.hpp +++ b/cpp05/ex03/Form.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/17 14:20:06 by rparodi #+# #+# */ -/* Updated: 2025/03/19 19:57:45 by rparodi ### ########.fr */ +/* Updated: 2025/03/19 20:29:51 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ class Form { Form(std::string const name, int execute, int sign); Form(Form const ©); Form& operator=(Form const &assign); - ~Form(); + virtual ~Form(); class GradeTooHighException : public std::exception { virtual const char *what() const throw() { return ("Error:\n> Grade is too high (have to be lower than 1)"); diff --git a/cpp05/ex03/Intern.cpp b/cpp05/ex03/Intern.cpp index 1187b3b..e298c19 100644 --- a/cpp05/ex03/Intern.cpp +++ b/cpp05/ex03/Intern.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/19 19:43:56 by rparodi #+# #+# */ -/* Updated: 2025/03/19 20:18:23 by rparodi ### ########.fr */ +/* Updated: 2025/03/19 20:29:04 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,7 @@ Intern::Intern() { std::cout << "[Intern] default constructor" << std::endl; + _ptr = NULL; } Intern::Intern(Intern const & copy) { @@ -31,6 +32,7 @@ Intern& Intern::operator= (Intern const & assign) { } Intern::~Intern() { + delete this->_ptr; std::cout << "[Intern] destructor" << std::endl; } @@ -41,16 +43,16 @@ Form* Intern::makeForm(std::string type, std::string target) { std::cout << "Intern creates " << type << std::endl; switch (i) { case 0: - return new ShrubberyCreationForm(target); + _ptr = new ShrubberyCreationForm(target); case 1: - return new RobotomyRequestForm(target); + _ptr = new RobotomyRequestForm(target); case 2: - return new PresidentialPardonForm(target); + _ptr = new PresidentialPardonForm(target); default: break; } } } std::cout << "Intern could not create " << type << std::endl; - return NULL; + return _ptr; } diff --git a/cpp05/ex03/Intern.hpp b/cpp05/ex03/Intern.hpp index f716459..408d308 100644 --- a/cpp05/ex03/Intern.hpp +++ b/cpp05/ex03/Intern.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/19 19:43:54 by rparodi #+# #+# */ -/* Updated: 2025/03/19 20:17:55 by rparodi ### ########.fr */ +/* Updated: 2025/03/19 20:29:37 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,8 @@ #include "ShrubberyCreationForm.hpp" class Intern { + private: + Form *_ptr; public: Intern(); Intern(Intern const & copy); diff --git a/cpp05/ex03/main.cpp b/cpp05/ex03/main.cpp index 8207035..5f779db 100644 --- a/cpp05/ex03/main.cpp +++ b/cpp05/ex03/main.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/16 14:47:26 by rparodi #+# #+# */ -/* Updated: 2025/03/19 20:21:34 by rparodi ### ########.fr */ +/* Updated: 2025/03/19 20:26:46 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */