From 98041eb6623690465ebe18c851649429dea65af8 Mon Sep 17 00:00:00 2001 From: yosyo Date: Tue, 26 Aug 2025 22:50:49 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(ex01):=20f?= =?UTF-8?q?ixed=20constructors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ex01/Span.cpp | 8 ++++---- ex01/Span.hpp | 8 ++++---- ex01/main.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ex01/Span.cpp b/ex01/Span.cpp index c7ba08d..0391d86 100644 --- a/ex01/Span.cpp +++ b/ex01/Span.cpp @@ -11,18 +11,18 @@ Span::Span(void) { } -Span::Span(unsigned int size) +Span::Span(const unsigned int &size) : _size(0), _max_size(size) { } -Span::Span(Span &other) +Span::Span(const Span &other) : _size(other._size), _max_size(other._max_size) { this->_data = other._data; } -Span &Span::operator=(Span &other) +Span &Span::operator=(const Span &other) { this->_max_size = other._max_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) throw std::runtime_error("max span size reached"); diff --git a/ex01/Span.hpp b/ex01/Span.hpp index 73eaf25..5eb4299 100644 --- a/ex01/Span.hpp +++ b/ex01/Span.hpp @@ -3,12 +3,12 @@ class Span { public: Span(void); - Span(unsigned int); - Span(Span &); - Span &operator=(Span &); + Span(const unsigned int &); + Span(const Span &); + Span &operator=(const Span &); ~Span(void); - void addNumber(int); + void addNumber(const int &); int shortestSpan(void); int longestSpan(void); diff --git a/ex01/main.cpp b/ex01/main.cpp index e48f492..7677123 100644 --- a/ex01/main.cpp +++ b/ex01/main.cpp @@ -3,7 +3,7 @@ int main() { - Span sp(5); + Span sp = Span(5); sp.addNumber(6); sp.addNumber(3); sp.addNumber(17);