首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小弟学习vector使用,想尝试使用上迭代器,遇到异常实在没招出来。请前辈们指教

2013-02-18 
小弟学习vector使用,想尝试使用下迭代器,遇到错误实在没招出来。请前辈们指教本帖最后由 xiaolongren1989

小弟学习vector使用,想尝试使用下迭代器,遇到错误实在没招出来。请前辈们指教
本帖最后由 xiaolongren1989 于 2013-01-28 16:17:48 编辑 #include <iostream>
#include <vector>
using namespace std;

template <typename T>
void Reverse (vector<T> &v) {
    vector<T> temp;
    if (v.empty()) {
        temp = v;
    } else {
        for (vector<T>::reverse_iterator rit = v.rbegin(); rit != v.rend(); rit++) {
            temp.push_back(*rit);
        }
    }
    v = temp;
}

int main () {
    vector<int> v;
    for (int i = 0; i < 5; i++) {
        v.push_back(i);
    }
    Reverse<int> (v);
    return 0;
}

小弟使用code:blocks下的gcc编译报出错误
11: error: expected ';' before 'rit'
11: error: 'rit' was not declared in this scope
:11: error: dependent-name 'std::vector::reverse_iterator' is parsed as a non-type, but instantiation yields a type

[解决办法]


typename vector<T>::reverse_iterator rit  ...试试

热点排行