有关模板的错误1

template <class T>
class Matrix{//矩阵
    friend istream& operator>>(istream&, Matrix<T>&);
    friend ostream
& operator<<(ostream&, Matrix<T>&);
public:
    Matrix(){mRow
=0, mCol=0, nZeroNum=0;}
private:
    vector
<Term<T>> vec;
    
int mRow,mCol;//矩阵的行数,列数
    int nZeroNum;//矩阵中的非零元素个数
};

报错:
test21.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 Matrix<int> &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$Matrix@H@@@Z)
test21.obj : error LNK2001: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Matrix<int> &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$Matrix@H@@@Z)
D:\DemoProject\test21\Debug\test21.exe : fatal error LNK1120: 2 unresolved externals

纠正如下:
template <class T>
class Matrix{//矩阵
    template<class T>
    friend istream
& operator>>(istream&, Matrix<T>&);
    template
<class T>
    friend ostream
& operator<<(ostream&, Matrix<T>&);
public:
    Matrix(){mRow
=0, mCol=0, nZeroNum=0;}
private:
    vector
<Term<T>> vec;
    
int mRow,mCol;//矩阵的行数,列数
    int nZeroNum;//矩阵中的非零元素个数
};

posted on 2008-10-26 16:44 deep2 阅读(259) 评论(0)  编辑 收藏 引用 所属分类: 错误集锦


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2008年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜