I am trying to change my program to work with templates. It works fine without templates but generates error 2019 when I use the templates.
//---------------------Vector.h code--------------------------------------
#include<iostream>
template <typename T>
class vectorClass
{
private:
int n; //# elements in vector
int capacity; //size of <g class="gr_ gr_31 gr-alert gr_gramm undefined Grammar only-ins doubleReplace replaceWithoutSep" data-gr-id="31" id="31"><g class="gr_ gr_33 gr-alert gr_spell
undefined ContextualSpelling ins-del multiReplace" data-gr-id="33" id="33">lowlevel</g></g> array
T* <g class="gr_ gr_34 gr-alert gr_spell undefined ContextualSpelling ins-del multiReplace" data-gr-id="34" id="34">elem</g>;
public:
vectorClass() :capacity(10), n(0)
{
elem = new T[capacity];
}
void pushback(T val);
void increase_capacity(T sz);
void print();
void popback();
void insert_atposition_value(int pos, T val);
T& operator[](int pos);
//const int& operator[](int pos)const;
};
//-----------------Vector.cpp------------------------------------------
#include "Vector.h"
template <typename T> void vectorClass<T>::pushback(T val)
{
if (n >= capacity)
increase_capacity(2 * capacity);
elem[n] = val;
n++;
}
template <typename T> void vectorClass<T>::increase_capacity(T sz)
{
if (sz <= capacity)
return;
int *p = new T[sz];
for (int i = 0; i < n; i++)
p[i] = elem[i];
capacity = sz;
delete[] elem;
elem = p;
}
template <typename T> void vectorClass<T>::print()
{
for (int i = 0; i < n; i++)
std::cout << elem[i];
}
template <typename T> void vectorClass<T>::popback()
{
elem[n - 1] = 0;
n--;
}
template <typename T>void vectorClass<T>::insert_atposition_value( int pos, T val)
{
if (pos > capacity)
std::cout << "Out of Bounds \n";
pushback(0);
for (int j = n - 1; j >= pos; --j)
elem[j] = elem[j - 1];
elem[pos] = val;
}
template <typename T> T & vectorClass<T>::operator[](int pos)
{
// TODO: insert return statement here
return elem[pos];
}
//const int & vector::operator[](int pos) const
//{
//
// TODO: insert return statement here
//
return elem[pos];
//}
![]()