Sign in to follow this  

STL and templates

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

This topic is 4864 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this