• Advertisement
Sign in to follow this  

C++ std::iterator templates (for cyclical access to a vector)

This topic is 3965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
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);
}



Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement