※ 引述《karate362 (最近腰不痛的卡拉特)》之銘言:
: 標題: [問題] HW5 compile error
: 時間: Wed Dec 20 10:38:35 2006
:
: 或許是我沒有搞清楚iterator的用法?
:
:
: 我在size()裡這樣寫
:
:
: iterator ni = begin();
:
: 按理說 begin()是傳回一個iterator
: 我也有多載化 = 的運算子
: 但他卻跟我說:
:
: error: passing 'const SList<LTestObj>' as 'this' argument of
: 'SList<T>::iterator SList<T>::begin()' discards qualifers
:
:
: 請問這是怎麼回事呢?
:
: 另外 SList是使用了template的類別
: 那麼在它自己的member function 宣告一個iterator的時候
: 不用寫SList<T>::iterator 寫iterator就可以嗎?
:
: 宣告一個SListnode時 語法一定要寫成SListnode<int> node 這樣的形式嗎?
:
:
: --
: ※ 發信站: 批踢踢實業坊(ptt.cc)
: ◆ From: 220.137.66.189
: 推 ric2k1:size() is a const method. Unless you want to implement 12/20 20:22
: 推 ric2k1:class const_iterator, please try to find some other way 12/20 20:22
OK. let me make it clearer---
The function "begin()" should have two prototypes:
1. iterator begin() {...}
2. const_iterator begin() const {...}
For this homework, you can choose to make the class more complete by
implementing class const_iterator and other const methods. Or think of some
workaround like "li = _head"...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.91.222.144