作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] HW5 compile error
时间Wed Dec 20 20:29:26 2006
※ 引述《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