作者dostaevsky (軒)
看板EE_DSnP
標題[問題] iterator declare and initialize
時間Wed May 20 13:53:20 2009
由於overloaded = 的prototype是
iterator& operator = (const iterator& i)
在ADT member function中如果要宣告並初始化iterator
若這樣寫
iterator it = this.begin();
會有error: request for member 'begin' in 'this',
which is of non-class type 'DList<AdtTestObj>* const'
我猜想是因為 = 需要reference to a const iterator
但begin return 的只是普通iterator
這樣寫也會有相同錯誤
iterator it(this.begin());
但如果要使用overloaded = 還要修改右邊成為const的話,感覺有點麻煩
請問有沒有能讓 = 順利使用的方法?? 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.224.44.162
1F:推 yangjiunru:應該是this->begin() or begin() 05/20 13:56
2F:推 wanga10219:因為this 是指標 05/20 20:19