diff --git a/ex02/Makefile b/ex02/Makefile new file mode 100644 index 0000000..45bb44c --- /dev/null +++ b/ex02/Makefile @@ -0,0 +1,26 @@ +CXX := c++ +CXXFLAGS := -std=c++98 -Wall -Wextra -Werror -g +SRCDIR := src +OBJDIR := obj +NAME := ex02 + +SRCS := $(wildcard $(SRCDIR)/*.tpp) +OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS)) + +all: $(NAME) + +$(OBJDIR)/%.o: $(SRCDIR)/%.cpp + mkdir -p $(OBJDIR) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(NAME): $(OBJS) + $(CXX) $(CXXFLAGS) $^ -o $@ + +clean: + rm -rf $(OBJDIR) + +fclean: clean + rm -fr $(NAME) + +re: fclean + @make --no-print-directory all \ No newline at end of file diff --git a/ex02/src/Array.hpp b/ex02/src/Array.hpp new file mode 100644 index 0000000..92a7cf1 --- /dev/null +++ b/ex02/src/Array.hpp @@ -0,0 +1,51 @@ +#pragma once + +template +class Array +{ + private: + T* _arr; + unsigned int _size; + + public: + Array(): + _arr(new T[0]), + _size(0) + {}; + Array(unsigned int n): + _arr(new T[n]), + _size(n) + {}; + Array(const Array& src) + { + new T[0]; + *this = src; + }; + + ~Array() + { + delete[] this->_arr; + }; + + Array& operator=(const Array& src)\ + { + if (this == &src) + return ; + delete[] this->_arr; + this->_size = src._size; + new this->_arr[src._size]; + for (size_t i = 0; i < src._size; i++) + this->_arr[i] = src._arr[i]; + }; + Array& operator[](unsigned int index) + { + if (i >= _size) + throw std::exception(); + return _array[i]; + }; + + unsigned int size() const + { + return _size; + }; +};