c++ - 带有自定义模板的 STL 迭代器

标签 c++ xcode gcc 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 到 size 的索引进行迭代是可行的,但这不是我更愿意实现此功能的方式。还有另一种解决方法吗? 谢谢

最佳答案

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

typename vector<T>::iterator it;

查找从属名称。开始here .

关于c++ - 带有自定义模板的 STL 迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/594521/

相关文章:

c++ - DirectWrite 文本位置因字体大小而异

ruby - 在 Mountain Lion 上使用 RVM 安装 ree-1.8.7

Xcode - UIViewController 中的 UICollectionView

c - 显然 NULL 在包含的文件中是未知的

python - 针叶林 'i586-linux-gnu-gcc' : No such file or directory

c - 改变 objective-c 标准有什么用吗?

c++ - 检查类型是否被声明为元类型系统(对于 SFINAE)

c++ - 简单类的 LNK2019 错误

c++ - OpenCV:HOGDescriptor.compute

ios - ScrollView 设置动画持续时间