How should I declare and use overloaded istream and ostream? This is my code:
in .hh file:
template <typename TypWart>
class matrix{
private:
bool poprawny;
int rozmiar;
TypWart *tab;
TypWart *wyniki;
TypWart *wyrazy;
wektor *z;
public:
void alokuj();
void gauss();
TypWart rozwiaz();
void wypisz();
void zamien(int k, int l);
void sprawdz();
zespolona& operator[](int x){
return tab[x];
}
wektor pomnoz(wektor W, wektor A);
wektor odejm(wektor W, wektor A);
wektor przypisz();
//matrix skopiuj(matrix M);
wektor przypisz2();
// wektor pierwiastek(wektor W);
wektor operator*(wektor W);
template <typename Typ>
friend istream& operator>>(istream& strm, matrix<Typ>& M);
template <typename Typ>
friend ostream& operator<<(ostream& strm, matrix<Typ>& M);
friend ostream& operator<<(ostream& strm, wektor W);
};
in .ccp file:
template <typename Typ>
istream& operator>>(istream& strm, matrix<Typ>& M){
int x,y;
//strm >> x >> y;
for(x=0; x<M.rozmiar; x++){
for(y=0; y<M.rozmiar; y++){
if(!(strm >> M.tab[y+(x*M.rozmiar)])) return strm;
}
}
for(x=0; x<M.rozmiar; x++) if(!(strm >> M.wyniki[x])) return strm;
return strm;
}
template <typename Typ>
ostream& operator<<(ostream& strm, matrix<Typ>& M){
int x,y;
//strm << x << " " << y << endl;
for(x=0; x<M.rozmiar; x++){
for(y=0; y<M.rozmiar; y++){
strm << M.tab[y+(x*M.rozmiar)];
strm << " ";
}
strm << endl;
}
return strm;
}
And the error I'm getting:
main.o: In function `main':
main.cpp:(.text+0x24): undefined reference to `std::basic_istream<char, std::char_traits<char> >& operator>><zespolona>(std::basic_istream<char, std::char_traits<char> >&, matrix<zespolona>&)'
collect2: ld returned 1 exit status
make: *** [a.out] Error 1
I tried adding <> to the declaration in .hh file but it didn't work. How do I fix this?