Compare commits

..

2 Commits

Author SHA1 Message Date
Camille Chauvet
e5bcc44b2e ex02: fix bozo bug 2023-10-04 15:27:58 +00:00
Camille Chauvet
cc70b96d30 ex02: add test 2023-10-04 15:27:25 +00:00
2 changed files with 29 additions and 3 deletions

View File

@ -24,7 +24,7 @@ class Array
Array(const Array& src)
{
new T[0];
this->_arr = new T[0];
*this = src;
};
@ -42,6 +42,7 @@ class Array
new T[src._size];
for (size_t i = 0; i < src._size; i++)
this->_arr[i] = src._arr[i];
return *this;
};
T& operator[](unsigned int index) const

View File

@ -24,14 +24,39 @@ int main()
}
}
std::cout << "Fill and get";
std::cout << "Fill and get" << std::endl;
{
unsigned int size = 10;
Array<int> t(size);
for (unsigned int i = 0; i != size; i++)
t[i] = i;
for (unsigned int i = 0; i != size; i++)
std::cout << i << std::endl;
std::cout << t[i] << std::endl;
}
std::cout << std::endl;
std::cout << "Copy and get" << std::endl;
{
unsigned int size = 10;
Array<int> t(size);
for (unsigned int i = 0; i != size; i++)
t[i] = i;
Array<int> b(t);
for (unsigned int i = 0; i != size; i++)
std::cout << b[i] << std::endl;
}
std::cout << std::endl;
std::cout << "operator = and get" << std::endl;
{
unsigned int size = 10;
Array<int> t(size);
for (unsigned int i = 0; i != size; i++)
t[i] = i;
Array<int> b;
b = t;
for (unsigned int i = 0; i != size; i++)
std::cout << b[i] << std::endl;
}
std::cout << std::endl;
}