It's my first time using templates and for some reason my program stops running, with a message that says "a problem caused the program to sop working correctly". I don't really know what's causing it.
Here's the main:
class point
{
int x;
int y;
public:
point(int abs=0,int ord=0)
{
x=abs;
y=ord;
}
~point(){}
};
the template:
template <class T>
class tablo
{
T *adr;
int nelem;
public:
tablo();
~tablo();
T nouvo(T);
T & operator [](T);
};
template <class T>
tablo<T>::tablo()
{
nelem=0;
adr=new T[nelem];
}
template <class T>
tablo<T>::~tablo()
{
delete[] adr;
}
template <class T>
T tablo<T>::nouvo(T var)
{
return adr[nelem++]=var;
}
template <class T>
T & tablo<T>::operator[](T var)
{
return[T]
}
and the main:
#include <iostream>
#include "point.h"
void main()
{
tablo<point> tab;
point a(1,2);
point b(3,4);
tab.nouvo(a);
tab.nouvo(b);
}