作者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