[問題] 書上c++code的問題想請教
我在看The C++ Programming Language時
P436 上面的Vector 有些問題
template<class T> class Itor {
public:
virtual T* first() = 0;
virtual T* next() = 0;
};
template<class T> Vector_itor : public Itor<T> {
Vector<T> &v; // question 1, why using ref?? why not just Vector<T> v;
size_t index;
public
Vector_itor(Vector<T>&vv) : v(vv), index(0) { }
T* first() { return (v.size()) ? &v[index=0] : 0;}
// question 2, why reset index to 0?
T* next() { return (++index<v.size()) ? &v[index] : 0; }
};
以上2個問題不太了解 希望知道的人可以提示一下
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.130.135.229
→
10/18 23:50, , 1F
10/18 23:50, 1F
→
10/18 23:55, , 2F
10/18 23:55, 2F
→
10/18 23:56, , 3F
10/18 23:56, 3F
→
10/19 01:07, , 4F
10/19 01:07, 4F
→
10/19 01:08, , 5F
10/19 01:08, 5F
→
10/19 01:09, , 6F
10/19 01:09, 6F
→
10/19 01:11, , 7F
10/19 01:11, 7F
→
10/19 01:12, , 8F
10/19 01:12, 8F
→
10/19 01:12, , 9F
10/19 01:12, 9F
→
10/19 01:13, , 10F
10/19 01:13, 10F
→
10/19 01:14, , 11F
10/19 01:14, 11F
→
10/19 01:14, , 12F
10/19 01:14, 12F
→
10/19 13:58, , 13F
10/19 13:58, 13F
→
10/19 13:59, , 14F
10/19 13:59, 14F
→
10/20 00:30, , 15F
10/20 00:30, 15F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章