🔨」 fix(ex01): fixed constructors

This commit is contained in:
2025-08-26 22:50:49 +02:00
parent 021636df08
commit 98041eb662
3 changed files with 9 additions and 9 deletions

View File

@@ -11,18 +11,18 @@ Span::Span(void)
{ {
} }
Span::Span(unsigned int size) Span::Span(const unsigned int &size)
: _size(0), _max_size(size) : _size(0), _max_size(size)
{ {
} }
Span::Span(Span &other) Span::Span(const Span &other)
: _size(other._size), _max_size(other._max_size) : _size(other._size), _max_size(other._max_size)
{ {
this->_data = other._data; this->_data = other._data;
} }
Span &Span::operator=(Span &other) Span &Span::operator=(const Span &other)
{ {
this->_max_size = other._max_size; this->_max_size = other._max_size;
this->_size = other._size; this->_size = other._size;
@@ -35,7 +35,7 @@ Span::~Span(void)
{ {
} }
void Span::addNumber(int value) void Span::addNumber(const int &value)
{ {
if (_size == _max_size) if (_size == _max_size)
throw std::runtime_error("max span size reached"); throw std::runtime_error("max span size reached");

View File

@@ -3,12 +3,12 @@
class Span { class Span {
public: public:
Span(void); Span(void);
Span(unsigned int); Span(const unsigned int &);
Span(Span &); Span(const Span &);
Span &operator=(Span &); Span &operator=(const Span &);
~Span(void); ~Span(void);
void addNumber(int); void addNumber(const int &);
int shortestSpan(void); int shortestSpan(void);
int longestSpan(void); int longestSpan(void);

View File

@@ -3,7 +3,7 @@
int main() int main()
{ {
Span sp(5); Span sp = Span(5);
sp.addNumber(6); sp.addNumber(6);
sp.addNumber(3); sp.addNumber(3);
sp.addNumber(17); sp.addNumber(17);