精華區beta C_and_CPP 關於我們 聯絡資訊
程式碼(錯的那行) friend ostream& operator << ( ostream& os , Stack<KeyType> &s); 錯誤顯示 [Warning] friend declaration `std::ostream& operator<< (std::ostream&, Stack<KeyType>&)' declares a non-template function [Warning] (if this is not what you intended, make sure the function template has already been declared and add < > after the function name here) -Wno-non-template-friend disables this warning 找好久都不知道錯誤所在 請問有高手可以幫忙嗎^^" -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.113.85
khoguan:暫時凍結!請讀公告依板規將標題改得更具體明確。 10/21 23:52
※ 編輯: richands 來自: 220.132.113.85 (10/22 01:31)
khoguan:解凍 10/22 01:44
richands:Sorry 10/22 02:59
> -------------------------------------------------------------------------- < 作者: khoguan (Khoguan Phuann) 看板: C_and_CPP 標題: Re: [問題] 請問friend 跟template有關的問題 時間: Sat Oct 22 02:17:57 2005 ※ 引述《richands (湛藍水色)》之銘言: : 程式碼(錯的那行) : friend ostream& operator << ( ostream& os , Stack<KeyType> &s); : 錯誤顯示 : [Warning] friend declaration `std::ostream& operator<< : (std::ostream&, Stack<KeyType>&)' declares a non-template function 要嘛 operator<< 這個 friend function 也必需是 function template template <class KeyType> friend ostream& operator << ( ostream& os , Stack<KeyType> &s); : [Warning] (if this is not what you intended, make sure the function : template has already been declared and add < > after the function : name here) -Wno-non-template-friend disables this warning 不嘛,或是寫成 friend ostream& operator<< <KeyType> ( ostream& os , Stack<KeyType> &s); 或 friend ostream& operator<< <> ( ostream& os , Stack<KeyType> &s); // 這樣寫較難看懂 但常常仍需在 class 外部宣告一個 template operator<< function -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.208.168
richands:感謝~ 問題已經解決 下次發文我會先注意的 抱歉^^" 10/22 03:02
richands:最後一段話 請問那邊要怎麼宣告呢? 10/22 03:02