--- /dev/null
+#include "Brain.h"
+#include <string>
+#include <iostream>
+
+Brain::Brain()
+{
+ std::cout << "Brain default cstr\n";
+}
+
+Brain::Brain(const Brain &other)
+{
+ std::cout << "Brain copy cstr\n";
+ *this = other;
+}
+
+Brain::~Brain()
+{
+ std::cout << "Brain destr\n";
+}
+
+Brain &Brain::operator=(const Brain &other)
+{
+ if (this == &other)
+ return (*this);
+ for (size_t i(0); i < CAPACITY; ++i)
+ ideas[i] = other.ideas[i];
+ return (*this);
+}
--- /dev/null
+#ifndef BRAIN_H
+# define BRAIN_H
+
+# include <string>
+
+class Brain
+{
+ private:
+ static const size_t CAPACITY = 100;
+
+ std::string ideas[CAPACITY];
+
+ public:
+ Brain();
+ Brain(const Brain &other);
+ ~Brain();
+
+ Brain &operator=(const Brain &other);
+};
+
+#endif // BRAIN_H
Cat::Cat()
: Animal("Cat")
+ , m_brain(new Brain)
{
std::cout << "Cat default cstr\n";
}
Cat::Cat(const Cat &other)
: Animal("Cat")
+ , m_brain(new Brain)
{
std::cout << "Cat copy cstr\n";
*this = other;
Cat::~Cat()
{
std::cout << "Cat destr\n";
+ delete m_brain;
}
Cat &Cat::operator=(const Cat &other)
{
if (this == &other)
return (*this);
+ *m_brain = *other.m_brain;
return (*this);
}
# define CAT_H
# include "Animal.h"
+# include "Brain.h"
class Cat : public Animal
{
private:
+ Brain *m_brain;
public:
Cat();
Dog::Dog()
: Animal("Dog")
+ , m_brain(new Brain)
{
std::cout << "Dog default cstr\n";
}
Dog::Dog(const Dog &other)
: Animal("Dog")
+ , m_brain(new Brain)
{
std::cout << "Dog copy cstr\n";
*this = other;
Dog::~Dog()
{
std::cout << "Dog destr\n";
+ delete m_brain;
}
Dog &Dog::operator=(const Dog &other)
{
if (this == &other)
return (*this);
+ *m_brain = *other.m_brain;
return (*this);
}
# define DOG_H
# include "Animal.h"
+# include "Brain.h"
class Dog : public Animal
{
private:
+ Brain *m_brain;
public:
Dog();
Dog.cpp \
WrongAnimal.cpp \
WrongCat.cpp \
+ Brain.cpp \
SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES))