具有自定义模板的 STL 迭代器
我有以下模板方法,
template <class T>
void Class::setData( vector<T> data )
{
vector<T>::iterator it;
}
并且收到以下编译错误( XCode/gcc )
错误:预期为“;” 在“它”之前
我发现其他人也有类似的问题 这里 (往下读会发现它是相同的,即使它开始时有不同的问题),但他们似乎已经通过更新 Visual Studio 解决了。 这让我猜测这是一个编译器问题并且它应该编译,对吗? 通过从 0 到 size 的索引进行迭代是可行的,但这不是我希望实现此函数的方式。 还有其他办法解决这个问题吗? 谢谢
i have the following template method,
template <class T>
void Class::setData( vector<T> data )
{
vector<T>::iterator it;
}
and i'm getting the following compilation error ( XCode/gcc )
error: expected `;' before 'it'
i found someone else with a similar problem here (read down to see it's the same even though it starts out with a different issue) but they seem to have resolved by updating Visual Studio. This makes me guess that it is a compiler issue and that it should compile, is that correct? Iteration via indexing from 0 to size works, however it is not the way i would prefer to implement this function. Is there another way around this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
何时使用
typename
关键字的经典案例。 希望您拥有#include
-ed向量
和迭代器
,并在范围内的某个位置拥有using namespace std;
。 用途:查找从属名称。 从此处开始。
Classic case of when to use the
typename
keyword. Hoping that you have#include
-edvector
anditerator
and have ausing namespace std;
somewhere in scope. Use:Look up dependent names. Start here.
我认为您缺少
typename
:I think you are missing a
typename
:尝试:
是否缺少
using
语句?Try:
Just is case it's a missing
using
statement?