Re: [問題] template list<T>iterator

看板C_and_CPP (C/C++)作者 (我要加入劍道社!)時間16年前 (2009/06/12 11:07), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《qazq (...)》之銘言: : private: : std::list <T> m_lst; : std::list <T>::iterator m_itor; <--- 加了這行就 build fail 了 typename std::list<T>::iterator m_itor; : public: : ---------------- : error C2146: 語法錯誤 : 遺漏 ';' (在識別項 'm_itor' 之前) : 請問是為什麼呢? : 謝謝大家! 因為在對 template 進行 parse 時,compiler 不知道 T 是什麼, 也無法推斷 list<T>::iterator 到底是個型別,亦或只是 list<T> 底下的 static member。加上 typename 關鍵字可以告訴 compiler 說:這邊的 iterator 是一個型別,這樣才能正確 parse。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.87.151.2

06/12 11:24, , 1F
嗯嗯嗯!可以了!謝謝你! :)
06/12 11:24, 1F
文章代碼(AID): #1ACSQ1dE (C_and_CPP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1ACSQ1dE (C_and_CPP)