[問題] C++ STL list的begin() 傳回iterator問題

看板C_and_CPP (C/C++)作者 (problem maker)時間12年前 (2013/12/17 15:53), 編輯推噓0(004)
留言4則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 在stl_list.h裡, list<T>的begin()傳回的形態是: iterator, iterator的本來面貌是: _List_iterator<_Tp,_Tp&,_Tp*> 但是begin()這個function的implementation是: { return (_Node*)(_M_node->_M_next); } 這裡_Node的形態是: _List_node 請問這到底是什麼原理? 實際傳回的形態是_List_node, 宣告的形態是_List_iterator, 這樣還可以過? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): 我看的stl source code應該是SGI的蠻早的open source... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 99.57.137.146

12/17 15:58, , 1F
隱姓轉型. 去看一下 _List_iterator 的建構式們
12/17 15:58, 1F

12/17 15:59, , 2F
他的constructor吃_Node*
12/17 15:59, 2F

12/17 16:00, , 3F
應該是 _List_iterator(_List_node_base *) 之類的
12/17 16:00, 3F

12/17 16:07, , 4F
看到了, 感恩指點啊兩位
12/17 16:07, 4F
文章代碼(AID): #1Ii0BrCw (C_and_CPP)
文章代碼(AID): #1Ii0BrCw (C_and_CPP)