vector<T>::iterator - 无效? [英] vector<T>::iterator - invalid?
本文介绍了vector<T>::iterator - 无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
g++不是类型"错误
以下内容无法编译:
1 template<typename T>
2 void foo(std::vector<T>::iterator & i)
3 {
4 }
在 Visual Studio 上,我收到以下错误:
On Visual Studio, I get the following errors:
>(2) error C2065: 'i' : undeclared identifier
>(4) warning C4346: 'std::vector<_Tp>::iterator' : dependent name is not a type
prefix with 'typename' to indicate a type
>(4) error C2182: 'foo' : illegal use of type 'void'
>(4) error C2998: 'int foo' : cannot be a template definition
推荐答案
std::vector
是一种依赖模板的类型参数,即T
.因此,您应该使用它作为前缀 typename
:
std::vector<T>::iterator
is a type that is dependent on a template parameter, namely T
. Therefore, you should prefix with it typename
:
template<typename T>
void foo(typename std::vector<T>::iterator & i)
{
}
这篇关于vector<T>::iterator - 无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文