c – 带自定义模板的STL迭代器

前端之家收集整理的这篇文章主要介绍了c – 带自定义模板的STL迭代器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下模板方法,

template <class T>
void Class::setData( vector<T> data )
{    
    vector<T>::iterator it;
}

我得到以下编译错误(XCode / gcc)

error: expected `;’ before ‘it’

我发现其他人有类似的问题here (read down to see it’s the same even though it starts out with a different issue),但他们似乎已通过更新Visual Studio解决.这让我觉得它是一个编译器问题而且它应该编译,这是正确的吗?通过索引从0到大小的迭代工作,但它不是我更喜欢实现此功能的方式.还有另一种方法吗?
谢谢

解决方法

何时使用typename关键字的经典案例.希望你有#include-ed vector和iterator并且有一个using namespace std;在范围的某个地方.使用:

typename vector<T>::iterator it;

查找依赖名称.开始here.

猜你在找的Xcode相关文章