Jump to content
  • Advertisement
Sign in to follow this  
Stoic

Advanced Templates VS2003 Question

This topic is 4024 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
Advertisement
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
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!