ex03 finished

This commit is contained in:
aortigos
2026-02-18 21:28:38 +01:00
parent 7539e90e6a
commit 57eefd3b37
3 changed files with 73 additions and 11 deletions

View File

@@ -23,16 +23,13 @@ Intern::Intern()
Intern::Intern(const Intern &other)
{
*this = other;
(void)other; // No atributes for copying
// std::cout << "Intern copy constructor called" << std::endl;
}
Intern& Intern::operator=(const Intern &other)
{
if (this != &other)
{
// Copy attributes here
}
(void)other; // No atributes for copying
// std::cout << "Intern copy assignment operator called" << std::endl;
return (*this);
}
@@ -41,3 +38,54 @@ Intern::~Intern()
{
// std::cout << "Intern destructor called" << std::endl;
}
//////////////////
// Creators //
//////////////////
AForm* Intern::createShrubbery(const std::string &target)
{
return new ShrubberyCreationForm(target);
}
AForm* Intern::createRobotomy(const std::string &target)
{
return new RobotomyRequestForm(target);
}
AForm* Intern::createPardon(const std::string &target)
{
return new PresidentialPardonForm(target);
}
AForm* Intern::makeForm(const std::string &formName, const std::string &target)
{
std::string formNames[3] = {
"shrubbery creation",
"robotomy request",
"presidential pardon"
};
typedef AForm* (Intern::*FormCreator)(const std::string&);
FormCreator creators[3] = {
&Intern::createShrubbery,
&Intern::createShrubbery,
&Intern::createPardon
};
for (int i = 0; i < 3; i++)
{
if (formName == formNames[i])
{
std::cout << "Intern creates "
<< formName
<< std::endl;
return (this->*creators[i])(target);
}
}
std::cout << "Intern cannot create \"" << formName
<< "\" because it doesn't exist"
<< std::endl;
return (NULL);
}