This one actually tells me visual studio has a problem and needs to close this code. I'm sure it's in the insert/write section, but I'm not sure what I did wrong. I'll post the rather simple cpp below it.
#include <iostream>
using namespace std;
template <class T>
class list
{
public:
static const int list::size=5;
list();
list(int);
void insert(T);
void remove(T);
bool empty();
void print();
~list();
private:
T *thelist;
int numinlist;
int newsize;
};
template <class T> list<T>::list() //default
{
T *thelist = new T[list::size];
numinlist=0;
newsize=5;
}
template <class T> list<T>::list(int in_size)
{
T *thelist = new T[in_size];
numinlist=0;
newsize=in_size;
}
template <class T> void list<T>::insert(T write)
{
if(numinlist < list::size)
{
thelist[numinlist] = write;
numinlist++;
cout << "Numinlist is now" << " " << numinlist << endl;
}
else
{
newsize++;
T *temp = new T[newsize];
for (int i = 0; i < newsize; i++)
{
temp[i] = thelist[i];
delete [] thelist;
}
T *thelist = new T[newsize];
for (int i = 0; i < newsize; i++)
{
thelist[i]= temp[i];
delete [] temp;
}
thelist[numinlist] = write;
numinlist++;
cout << "Numinlist is now" << " " << numinlist << endl;
}
}
template <class T> void list<T>::remove(T) //remove function
{
if(numinlist > 0)
{
numinlist--;
cout << "Numinlist is now" << " " << numinlist << endl;
}
else
{
cout << "List is empty" << endl;
exit(1);
}
}
template <class T> bool list<T>::empty() //detect empty function
{
if(numinlist == 0)
{
cout << "List is empty" << endl;
return true;
}
else
{
cout << "List is not empty" << endl;
return false;
}
}
template <class T> void list<T>::print() //print function
{
cout << thelist <<endl;
}
template <class T> list<T>::~list()
{
}
Here is the cpp file
#include "templab.h"
typedef list<int> mylist;
int main()
{
mylist mylist;
mylist.insert(5);
mylist.insert(4);
mylist.insert(3);
mylist.insert(2);
mylist.insert(1);
mylist.insert(6);
mylist.remove(6);
mylist.remove(2);
mylist.remove(3);
mylist.print();
return 0;
}