Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 4148 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());
		return (itr + 1);

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!