-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrain.cpp
More file actions
46 lines (40 loc) · 853 Bytes
/
Brain.cpp
File metadata and controls
46 lines (40 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Brain.hpp"
#include "print.hpp"
Brain::Brain () { print ("Brain default constructor called"); }
Brain::Brain (const Brain &other)
{
print ("Brain copy constructor called");
*this = other;
}
Brain &
Brain::operator= (const Brain &other)
{
print ("Brain assigment operator called");
if (this != &other)
{
for (int i = 0; i < 100; i++)
this->_ideas[i] = other._ideas[i];
}
return *this;
}
Brain::~Brain () { print ("Brain destructor called"); }
void
Brain::setIdea (const std::string &idea, int index)
{
if (index < 0 || index >= 100)
{
print ("Index out of range");
return;
}
this->_ideas[index] = idea;
}
std::string
Brain::getIdea (int index) const
{
if (index < 0 || index >= 100)
{
print ("Index out of range");
return "";
}
return this->_ideas[index];
}