template <class T>
class Term{//矩阵中每个三元组的元素
public:
Term(int r,int c,T v):row(r),col(c),val(v){}
//private:
int row, col;//元素的行标,列标
T val;//元素的值
friend class Matrix<T>;
};
编译错误如下:
d:\demoproject\test21\test21\test21.cpp(21) : see reference to class template instantiation 'Term<T>' being compiled
d:\demoproject\test21\test21\test21.cpp(20) : error C2238: unexpected token(s) preceding ';'
d:\demoproject\test21\test21\test21.cpp(35) : error C2989: 'Matrix' : class template has already been declared as a non-class template
d:\demoproject\test21\test21\test21.cpp(20) : see declaration of 'Matrix'
d:\demoproject\test21\test21\test21.cpp(23) : error C3857: 'Matrix': multiple template parameter lists are not allowed
d:\demoproject\test21\test21\test21.cpp(38) : error C2143: syntax error : missing ')' before '<'
纠正如下:
template<class T>
class Matrix;
template <class T>
class Term{//矩阵中每个三元组的元素
public:
Term(int r,int c,T v):row(r),col(c),val(v){}
//private:
int row, col;//元素的行标,列标
T val;//元素的值
friend class Matrix<T>;
};