Sign in to follow this  

Advanced Templates VS2003 Question

This topic is 3745 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 All - I'm designing a templated "Sequence" class, and it won't let me compile a particular line of code...
template <class T, class NUMERIC=float>
class SequenceEvent;

template <class T, class NUMERIC=float>
class Sequence
{
    typedef std::vector<SequenceEvent<T, NUMERIC> > SequenceContainer;  //compiles fine

    typedef std::vector<SequenceEvent<T, NUMERIC> >::iterator  SequenceIter;  //Compiler Error

   // typedef std::vector<int>::iterator  SequenceIter;  //would compile fine....

};

I know that the templated typedef namespace stuff is pretty hard on the compiler, but this should be legal C++. I'm basing my design off of some of Andrei Alexandrescu's code. It's not compiling under VS 2003 or VS 2005. Does anyone have any idea what I can do to get around this? The basic idea is that I want the Sequence to be able to return iterators to SequenceEvents in other Sequence functions, but I want to be able to swap out the container tha the Sequence uses fairly easily. Thanks for any help!

Share this post


Link to post
Share on other sites
Try:
typedef typename std::vector<SequenceEvent<T, NUMERIC> >::iterator  SequenceIter;
A Google search for, say, 'c++ typename dependent name' will most likely lead you to an explanation of why the typename keyword is necessary here.

Share this post


Link to post
Share on other sites
You need the typename keyword.


template <class T, class NUMERIC=float>
class SequenceEvent;

template <class T, class NUMERIC=float>
class Sequence
{
typedef std::vector<SequenceEvent<T, NUMERIC> > SequenceContainer; //compiles fine

typedef typename std::vector<SequenceEvent<T, NUMERIC> >::iterator SequenceIter; //Compiler Error

// typedef std::vector<int>::iterator SequenceIter; //would compile fine....

};

Share this post


Link to post
Share on other sites

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