[問題] 新手Overloading operator ==問題請益
開發平台(Platform): (Ex: Win10, Linux, ...)
macOS中安裝Vs Code
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
gcc編譯
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
想請問各位大大~小弟新手,
練習時利用重載operator==運算符,想要實現在List中利用List的.remove()傳入自
定義數據類型,但卻報此錯誤:
錯誤結果(Wrong Output):
johnsu@MacBook-Pro list % g++ list.cpp -o main.out
In file included from list.cpp:4:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/list:2150:18:
error:
invalid operands to binary expression ('const
std::__1::__list_const_iterator<Hero, void
*>::value_type' (aka 'const Hero') and 'const
std::__1::list<Hero, std::__1::allocator<Hero>
>::value_type' (aka 'const Hero'))
if (*__i == __x)
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
http://codepad.org/7tWj0gSC
補充說明(Supplement):
我嘗試過再重載參數裡面傳入const Hero& h跟沒有const的版本,報的錯誤是相同的。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.71.198.39 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1591507107.A.45E.html
→
06/07 13:52,
4年前
, 1F
06/07 13:52, 1F
→
06/07 13:52,
4年前
, 2F
06/07 13:52, 2F
→
06/07 13:52,
4年前
, 3F
06/07 13:52, 3F
→
06/07 13:56,
4年前
, 4F
06/07 13:56, 4F
謝謝回覆!完全可以了,Header部分也非常感謝!我會注意這個習慣。
→
06/07 14:00,
4年前
, 5F
06/07 14:00, 5F
→
06/07 14:01,
4年前
, 6F
06/07 14:01, 6F
→
06/07 14:01,
4年前
, 7F
06/07 14:01, 7F
感謝回覆!我可能新手還比較看不懂錯誤訊息,已經利用const member function 解決
※ 編輯: john2223k (39.8.37.17 臺灣), 06/07/2020 14:51:00
→
06/07 15:15,
4年前
, 8F
06/07 15:15, 8F
→
06/07 15:15,
4年前
, 9F
06/07 15:15, 9F
感謝,確實是噴出一大串,有寫第幾行錯誤的訊息,不過因為實在太長就沒有貼出~會練
習閱讀這些訊息
※ 編輯: john2223k (39.8.37.17 臺灣), 06/07/2020 15:18:43
推
06/08 01:05,
4年前
, 10F
06/08 01:05, 10F