ex02
This commit is contained in:
parent
23311296d0
commit
066d646cf5
26
ex02/Makefile
Normal file
26
ex02/Makefile
Normal file
@ -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
|
51
ex02/src/Array.hpp
Normal file
51
ex02/src/Array.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
template<typename T>
|
||||
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;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user