Jump to content
  • Advertisement
Sign in to follow this  
bobster

STL and templates

This topic is 5077 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

Hi, a quick question about using STL inside templates. When creating a template class I get a compile error whenever I declare a STL vector iterator of a particular type, for instance:
#include <vector>
using namespace std;

template <class T>
class TestClass {
vector<T>::iterator test_it;
}

generates a compile error, however it compiles fine when I remove the <T> from the iterator declaration. Is it not necessary to define the type of vector you are going to use the iterator with when declaring it, and will leaving out the <T> cause me problems later?

Share this post


Link to post
Share on other sites
Advertisement
you need to use typename to notify the compiler than the iterator vector template member is a type upon instantiations.

IE

#include <vector>
using namespace std;

template <class T>
class TestClass {
typename vector<T>::iterator test_it;
}

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!