Hi
I have made a template which is suppose to to be a generic container for other data types suchs as int, floats and soo. it works fine with int, floats. But it doesn´t work with my own class type XTime could any one help me with this.
The function below gives me the error code "illegal structure operation for the if statement.
template <class Type>
bool G_container<Type>::contains(Type x) const{
for(int i=0;i<storlek;i++)
if(x == array[i])
return true;
return false;
}
Also second question does any one know how I can specify an otream overload for XTime in my container class. This one also gives me the error code ileegal structure operation. . I tried the following overload but it doesnt work.
template <class XTime>
ostream &operator<<(ostream &os, const G_container<XTime> &x){
for(int i=0;i< x.storlek;i++)
os << x.array[i].display(true) << ' ';
os << "\nSize " << x.storlek << " Allokerad " << x.allokerad;
return os;
}
The XTime class is declared as follows:
class XTime{
public:
//Konstruktor
XTime(): t(0), m(0), s(0) {}
XTime (int tim, int min, int sek);
void set(int tim, int min, int sek);
int read_tim() const {return tim;}
int read_min() const {return m;}
int read_sek() const {return s;}
void display(bool write_sec) const;//display t,m,s
// some operator/s are needed here,
// if this class is to work with G_container
private:
int t, m, s;
};