Starting ex02 from zero
This commit is contained in:
@@ -16,6 +16,24 @@
|
||||
|
||||
# include <iostream>
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Array<T>::Array(unsigned int n)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Array(const Array &other)
|
||||
{
|
||||
if (this != other)
|
||||
{
|
||||
this->element = other.element;
|
||||
this->size = other.size;
|
||||
}
|
||||
return (*this);
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Array &operator=(const Array &other)
|
||||
{
|
||||
this = other;
|
||||
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
~Array()
|
||||
{
|
||||
delete[] T;
|
||||
|
||||
}
|
||||
|
||||
Array(unsigned int n)
|
||||
template <typename T>
|
||||
T &operator[](unsigned int i)
|
||||
{
|
||||
this->size = n;
|
||||
|
||||
}
|
||||
|
||||
int size()
|
||||
template <typename T>
|
||||
unsigned int size() const
|
||||
{
|
||||
return (this->size);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user