一个错误,谁来看看
#include <iostream> #include <cstdlib> using namespace std; const int DefaultSize=100; template <class T> struct Trituple{ int row,col; T value; Trituple<T>& operator =(Trituple<T>& x){ row=x.row;col=x.rol;value=x.value; } }; template <class T> class SparseMatrix{ public: friend ostream& operator <<(ostream& out,SparseMatrix<T>& M); friend ostream& operator >>(ostream& in,SparseMatrix<T>& M); SparseMatrix(int maxSz=DefaultSize); ~SparseMatrix(){delete []smArray;} SparseMatrix<T>& operator =(SparseMatrix<T>& x); SparseMatrix<T> trans(); SparseMatrix<T> Add(SparseMatrix<T>& x); private: int Rows,Cols,Terms; Trituple<T> *smArray; int maxTerms; }; template <class T> SparseMatrix<T>::SparseMatrix(int maxSz):maxTerms(maxSz){ smArray=new Trituple<T>[maxSz]; Rows=Cols=Terms=0; }/* template <class T> ostream& operator <<(ostream& out,SparseMatrix<T>& M){ out<<"rows="<<M.Rows; out<<"clos="<<M.Cols; out<<"terms="<<M.Terms; for(int i=0;i<M.Terms;i++){ out<<"M["<<M.smArray[i].row<<"]["<<M.smArray[i].col<<"]="<<M.smArray[i].value; } return out; }*/
//下面这段本来是没有的
ostream& operator <<(ostream& out,SparseMatrix<int>& M){ out<<"rows="<<M.Rows; out<<"clos="<<M.Cols; out<<"terms="<<M.Terms; for(int i=0;i<M.Terms;i++){ out<<"M["<<M.smArray[i].row<<"]["<<M.smArray[i].col<<"]="<<M.smArray[i].value; } return out; } int main(){ SparseMatrix<int> s(100); cout<<s; return 0; }
这个吧那一段注释了,按道理是用T的,可是编译不过,不知道是为什么?????