I am creating a template class for working with matrices and get an error when I try to use the overloaded << operator.
This is the code:
#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
template <class T>
class matrice
{
T **a;
int m,n;
public:
matrice();
matrice(int,int);
matrice(FILE *);
matrice(int,int,T **);
matrice(matrice &x);
~matrice(){}
T& operator[](int i){return a[i];}
friend T operator+(matrice<T> &a,matrice<T> &b);
friend T operator+(T x,matrice<T> &b);
friend T operator-(matrice<T> &a,matrice<T> &b);
friend T operator-(T x,matrice<T> &b);
friend T operator*(matrice<T> &a,matrice<T> &b);
friend T operator*(T x,matrice<T> &b);
friend T operator/(matrice<T> &a,matrice<T> &b);
friend T operator/(T x,matrice<T> &b);
bool operator ==(T &b);
bool operator !=(T &b);
friend ostream &operator <<(ostream &,matrice<T> &);
T transpusa(){}//= si strcpy
//virtual T determinant();
T inversa(){}
int getNrLinii(){
return m;
}
int getNrColoane(){
return n;
}
void setElement(int,int,T);
};
template <class T>
ostream &operator<<(ostream &os, matrice<T> &b){
int i,j;
for(i=0;i<b.m;i++){
for(j=0;j<b.n;j++){
os<<b[i][j]<<" ";
}
os<<endl;
}
return os;
}
matrice<char *>::matrice(int linii,int col):m(linii),n(col){
int i,j;
a=new char**[m];
for(i=0;i<m;i++){a[i]=new char*[n];}
for(i=0;i<m;i++)
for(j=0;j<n;j++){
cout<<"a["<<i<<"]["<<j<<"]= ";
char *tmp;
tmp=new char[100];
cin>>tmp;
a[i][j]=new char[strlen(tmp)+1];
strcpy(a[i][j],tmp);
delete tmp;
}
}
//friend class Iterator;
void main (int argc, char * const argv[]) {
matrice<char *> m1(2,2);
cout<<m1;
cout<<m1.getNrLinii();
getch();
}
This is the error I get:
1>proiect.obj : error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class matrice<char *> &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$matrice@PAD@@@Z)
What am I missing? I am using visual studio express 2010