Starting ex02 from zero

This commit is contained in:
aortigos
2026-03-22 21:27:19 +01:00
parent 5c54cbee03
commit 5eae0db20d
2 changed files with 62 additions and 37 deletions

View File

@@ -16,6 +16,24 @@
# include <iostream>
# include "Array.tpp"
template <typename T>
class Array
{
private:
T *data;
unsigned int _size;
public:
Array();
Array(unsigned int n);
Array(const Array &other);
Array &operator=(const Array &other);
~Array();
T &operator[](unsigned int i);
unsigned int size() const;
};
#include "Array.tpp"
#endif

View File

@@ -6,49 +6,56 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/21 17:09:36 by aortigos #+# #+# */
/* Updated: 2026/03/21 17:11:51 by aortigos ### ########.fr */
/* Updated: 2026/03/22 14:52:48 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
// Construction with no parameter -> creates an empty array
// Construction with an unsigned int n as parameter
// Consctrucion by copy and assignment operator
// operator new [] to allocate memory
// Access elements by operator []
// Exception if access index out of bounds
// Function size
template <typename T>
class Array
Array<T>::Array() : data(NULL), _size(0)
{
private:
T *element;
unsigned int size;
public:
Array()
{
new T[n]();
}
// std::cout << "Default constructor called" << std::endl;
}
Array(const Array &other)
{
if (this != other)
{
this->element = other.element;
this->size = other.size;
}
return (*this);
}
template <typename T>
Array<T>::Array(unsigned int n)
{
Array& operator=(const Array &other)
{
this = other;
}
}
~Array()
{
delete[] T;
}
template <typename T>
Array(const Array &other)
{
Array(unsigned int n)
{
this->size = n;
}
}
int size()
{
return (this->size);
}
};
template <typename T>
Array &operator=(const Array &other)
{
}
template <typename T>
~Array()
{
}
template <typename T>
T &operator[](unsigned int i)
{
}
template <typename T>
unsigned int size() const
{
}