首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

LNK2019: 无法解析的外部符号解决方法

2012-03-04 
LNK2019: 无法解析的外部符号classMatrix{private:intRows,Cols,TermsTerm TypesmArray[maxLen]public

LNK2019: 无法解析的外部符号
class   Matrix{
private:
int   Rows,   Cols,   Terms;
Term <Type>   smArray[maxLen];  
public:
Matrix <Type>   Transpose();
Matrix <Type>   FastTranspose();
Matrix <Type>   Multiply(Matrix <Type>   b);
Matrix(int   row,   int   col):Rows(row),Cols(col){}
friend   ostream&   operator < <(ostream&,
                                                                    const   Matrix <Type> &);
friend   istream&   operator> > (istream&,   Matrix <Type> &);
};
ostream&   operator < <(ostream&   os,const   Matrix <Type> &   m){
for(int   i   =   0;   i   <   m.Rows;   i++){
for(int   j   =   0;   j   <   m.Cols;   j++)
for(int   k   =   0;   k   <   m.Terms;   k++)
if(m.smArray[k].row   ==   i   &&   m.smArray[k].col   ==   j)
os   < <   m.smArray[k].value   < <   "   ";
else
os   < <   0   < <   "   ";  
os   < <   endl;
}
return   os;
}
int   _tmain(int   argc,   _TCHAR*   argv[])
{
Matrix <int>   a(2,3);
Matrix <int>   b(3,4);
ofstream   out( "out.txt ");
cout   < <   a;//连接出错
return   0;
}
当cout < <   a;时程序没有问题
以下为错误信息
SparseMatrix.obj   :   error   LNK2019:   无法解析的外部符号   "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>   const   &) "   (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Matrix@H@@@Z),该符号在函数   _wmain   中被引用
C:\Documents   and   Settings\Administrator\My   Documents\Visual   Studio   2005\Projects\SparseMatrix\Debug\SparseMatrix.exe   :   fatal   error   LNK1120:   1   个无法解析的外部命令


[解决办法]
你建win32控制台程序吧

这个错误是库没有正确包含进去


[解决办法]
class Matrix{
前面没有了?应该还有template之类的吧?不然按你的写法,Matrix不是一个模板类
ostream& operator < <(ostream& os,const Matrix <Type> & m){
...
}
这种写法也不对,Type是什么东东啊?如果是模板参数,那么前面就应该还有template一行。
[解决办法]
有些头文件或者LIB没有加到环境中去

热点排行