Manually I can create a std::vector<int>::iterator
object like:
std::vector<int>::iterator i;
So here std::vector<int>::iterator
is a type. But when I write a function :
template <class T>
std::vector<T>::iterator foo(std::vector<int>::iterator i)
{
return i;
}
The compiler shows a warning :
std::vector<T>::iterator' : is a dependent name not a type
and the code does not compiles. But if in main I call the function like this:
int main()
{
vector<int> v;
foo(v.begin());
}
The parameter T
should be resolved. Then why compiler is showing error?
You have to prefix it with Typename
std::vector<T>::iterator
is dependent on a template parameter, namely T
.Therefore,you should prefix with it typename:
Try using:
typename std::vector<T>::iterator
You can refer This :http://pages.cs.wisc.edu/~driscoll/typename.html
Following link has a solution and answer,
"Dependent Name is not a Type", but prefixing with "typename" causes compiler crash
In short, "std::vector::iterator" is a dependent name not a typename. So you can not use directly as a typename. You have to specify "typename std::vector::iterator".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With