回別人的文順便貼一下 Q: 要怎麼更動set 中element 的內容呢? A: Visual C++ Team Blog 昨天也有提到這個問題 請看問題三:http://0rz.tw/TNBKr 在C++98/03 中,使用者是可以任意更改元素的值,只要不要改變元素順序 但在C++0x,明確的限制了這件事 "Keys in an associative container are immutable" (N2857 23.2.4/5) and "For [set and multiset], both iterator and const_iterator are constant iterators" 他提出了四種解法 1 改用 map/multimap,分離key 和value 2 刪掉改一改再塞一個新的進去 3 改用 set/multiset, comparator>,多一層轉換 4 上一篇推文中提到的 mutable (作者這說很怪 weird), const_cast (作者說這很邪惡 evil) 雖然 C++0x 都快變成C++1x了,還是要尊重一下...:P
文章標籤
全站熱搜
創作者介紹
創作者 cmchao 的頭像
cmchao

軟趴趴

cmchao 發表在 痞客邦 留言(0) 人氣(249)