加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 18:10:00 所属栏目:百科 来源:网络整理
导读:我有以下模板方法, template class Tvoid Class::setData( vectorT data ){ vectorT::iterator it;} 我得到以下编译错误(XCode / gcc) error: expected `;’ before ‘it’ 我发现其他人有类似的问题here (read down to see it’s the same even though it s
我有以下模板方法,

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读