>" type="hidden"/>

error LNK2019: 無法解析的外部符號 "class std::basic_ostream >


1,VS2013:

錯誤 1 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 Stack<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Stack@H@@@Z),該符號在函數 _main 中被引用 C:\Users\Administrator\documents\visual studio 2013\Projects\leetcodeTree\leetcodeTree\leetcodeTree.obj leetcodeTree

錯誤 2 error LNK1120: 1 個無法解析的外部命令 C:\Users\Administrator\documents\visual studio 2013\Projects\leetcodeTree\Debug\leetcodeTree.exe leetcodeTree

(鏈接錯誤)出錯原因:

在類內聲明友元函數時,需要在上面加上 模板頭 template<class T>。(具體原因還不是很清楚)

解決辦法:

(a)在上面加上一行模板頭即可。

(b)聲明時使用  friend ostream& operator<< <>(ostream& os, const Stack<T>&) 可以解決。(多加了一個 <>)

更加詳細的討論點擊這里


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM