template <class T>
vector<T>::iterator getnext(vector<T> &inset,vector<T>::iterator &itr)
{
if (itr == (inset.end()-1) )
{
return (inset.begin());
}
else
return (itr + 1);
}
C++ std::iterator templates (for cyclical access to a vector)
Hey,
I am trying to template the following code. I have a function that allows vector to be used in a cyclical way. Firstly, is there allready an implementation of this in the std library that I have overlooked? Secondly, I cannot get the template to compile. I get the following, in addition to a syntax error.
c:\dev\classes\tt3dfont.cpp(56): warning C4346: 'std::vector<_Ty::Type>::iterator' : dependent name is not a type
From the help on this error I think I need to use typename, but I am unsure how. The code works fine when not templated (fx vector<int>)
In addition, I suspect it may be possible to remove the need for first parameter (the actual vector) to be removed. There may be a better way to code this anyway, any suggestions would be helpful.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement