fix: use abstract

This commit is contained in:
Camille Chauvet 2023-08-09 16:20:39 +00:00
parent 882131784b
commit cdd8fd1645
9 changed files with 20 additions and 7 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
ex0*/obj/*.o
ex0*/ex0*

View File

@ -10,6 +10,7 @@ Cat::Cat()
Cat& Cat::operator=(const Cat& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
@ -22,6 +23,7 @@ Cat::~Cat()
Cat::Cat(const Cat& src): Animal()
{
this->brain = new Brain();
*this = src;
}

View File

@ -11,6 +11,7 @@ Dog::Dog()
Dog& Dog::operator=(const Dog& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
@ -23,6 +24,7 @@ Dog::~Dog()
Dog::Dog(const Dog& src): Animal()
{
this->brain = new Brain();
*this = src;
}

View File

@ -15,6 +15,10 @@ int main()
delete i;
const WrongAnimal* k = new WrongCat();
k->makeSound();
Dog test;
{
Dog test2 = test;
}
delete k;
return 0;
}

View File

@ -23,11 +23,6 @@ AAnimal::~AAnimal()
std::cout << "~AAnimal()" << std::endl;
}
void AAnimal::makeSound() const
{
std::cout << "OuGAABounga" << std::endl;
}
std::string AAnimal::getType() const
{
return this->type;

View File

@ -12,7 +12,7 @@ class AAnimal
std::string getType() const;
virtual void makeSound() const;
virtual void makeSound() const = 0;
protected:
std::string type;

View File

@ -10,6 +10,7 @@ Cat::Cat()
Cat& Cat::operator=(const Cat& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
@ -22,6 +23,7 @@ Cat::~Cat()
Cat::Cat(const Cat& src): AAnimal()
{
this->brain = new Brain();
*this = src;
}

View File

@ -11,6 +11,7 @@ Dog::Dog()
Dog& Dog::operator=(const Dog& src)
{
*this->brain = *src.brain;
this->type = src.type;
return *this;
}
@ -23,6 +24,7 @@ Dog::~Dog()
Dog::Dog(const Dog& src): AAnimal()
{
this->brain = new Brain();
*this = src;
}

View File

@ -11,6 +11,10 @@ int main()
delete j;
const AAnimal* i = new Cat();
delete i;
// const AAnimal* meta = new AAnimal();
Dog test;
{
Dog test2 = test;
}
//const AAnimal* meta = new AAnimal();
return 0;
}