由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 实现vector的iterator,template问题
相关主题
iterator 实现 如何 peek(),pop()?[google面试]iterator访问
请教 Iterator 一题问一道题
问个题贴一个C++ nested Iterator的code,求讨论和指正。
问一道C++ template的面试题调试成功的next_permutation代码
Google店面leetcode 的 Insert Interval 就是过不了大的
Two problems from GoogleScala怎么通过index访问set或者array
面完G的电面了,忐忑刷了半天题
新鲜G面经LC的BST iterator到底要考察什么?
相关话题的讨论汇总
话题: vector话题: vec话题: hasnext话题: iterator话题: end
进入JobHunting版参与讨论
1 (共1页)
f**********t
发帖数: 1001
1
实现了vector的iterator,包括Next(), hasNext(), peek()等功能。
但是一旦用template写又卡住了。
这里vector::iterator it; 会出错:missing ";" before identifier "it"
感觉是个编译问题,但不知怎么fix. 求指教。多谢!=)
template class VectorIterator {
vector vec_;
vector::iterator it;
public:
VectorIterator(vector &vec) {
vec_ = vec;
it = vec_.begin();
}
bool hasNext() {
return it != vec_.end();
}
T next() {
if (!hasNext()) {
throw exception("End of vector");
}
T val = *it;
++it;
return val;
}
T peek() {
if (!hasNext()) {
throw exception("End of vector");
}
return *it;
}
};
I*********g
发帖数: 93
1 (共1页)
进入JobHunting版参与讨论
相关主题
LC的BST iterator到底要考察什么?Google店面
what is the internal implementation of DequeTwo problems from Google
zynga, linkedin, epic, two sigma, facebook面经面完G的电面了,忐忑
hasNext的迭代器题怎么做?新鲜G面经
iterator 实现 如何 peek(),pop()?[google面试]iterator访问
请教 Iterator 一题问一道题
问个题贴一个C++ nested Iterator的code,求讨论和指正。
问一道C++ template的面试题调试成功的next_permutation代码
相关话题的讨论汇总
话题: vector话题: vec话题: hasnext话题: iterator话题: end