Bez STL. Napisz szablon Array<T>- klasy będącej tablicą o zmiennym rozmiarze zawierającej elementy typu T. Zaimplementuj:
a)konstruktor i deklracje
b)destruktor
c)void dodaj(T &t)- dodaje element na końcu
d)bool usun(int i)- usuwa i-ty element, zwraca false jeśli takiego brak
e)operator przypisania
#include <iostream>
using namespace std;
template <typename T> class Array{
T *tab;
int size;
int used_size;
public:
Array(){
size=0;
tab=NULL;
}
Array(int size){
this->size=size;
tab=new T[size];
used_size=0;
}
~Array(){
if(size!=0){
delete[]tab;
size=0;
}
else return;
}
void dodaj(T &t){
if(used_size<size){
used_size++;
for(int i=0;i<size;i++){
if(i!=size-1) tab[i]=tab[i+1];
else tab[i]=t;
}
}
}
bool usun(int i){
for(int j=0;j<used_size;j++){
if (j==i) return tab[i];
else return false;
}
}
/*Array &operator=(Array<T> &t){
this->size=t.size;
tab[size]=t.tab;
return *this;
}*/
};
Czy mógłby ktoś powiedzieć mi, co robię źle i pomóc mi to poprawić? Z góry dziękuję.