关于在类模板中实现友元函数的问题
Veini 2007-09-10 02:28:10 编写一个类模板,在类模板中重载了运算符,并把该函数声明为友元函数.如果在类体外定义该友元函数,则出现如下编译错误:
main.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 SeqList<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$SeqList@H@@@Z),该符号在函数 _main 中被引用
D:\c++练习\SeqList\Debug\SeqList.exe : fatal error LNK1120: 1 个无法解析的外部命令
如果是在类模板中直接定义该友元函数,则能成功编译并运行.这是为什么?