"too few template arguments" in STL, Visual Studio 9.0

So here's the problem.

A piece of software for a company I work for is written in STL.  This software compiled fine in Visual Studio 2005.  However, after upgrading to Visual Studio 2008, some of the STL code fails to compile, with this error:

'std::iterator' : too few template arguments

I see the error on three lines of code, each of which have iterator<_Ty> on them.  I know a little bit about STL but not a whole lot, so I am having trouble getting to the root of the problem.  I have tried adding additional arguments to the iterator<_Ty> portion, but then I get the reverse error: 'too many template arguments' even if I have only added one.

This used to work just fine in Studio 2005!!   I checked the template declarations in 2008 and they are slightly different from 2005 but not in a way that I can see would affect this... Does anyone know what might be wrong?

Code snippet attached.

template <class _Ty>
  class reverse_iterator : public const_reverse_iterator<_Ty>
    reverse_iterator() { }
    explicit reverse_iterator(iterator<_Ty> other) : const_reverse_iterator<_Ty>(other) { }
    template <class _Other> operator reverse_iterator<_Other> () { return *(reverse_iterator<_Other> *)(this); }
    template <class _Other> operator const reverse_iterator<_Other> () const { return *(const reverse_iterator<_Other> *)(this); }
    template <class _Other> operator const_reverse_iterator<_Other> () { return *(const_reverse_iterator<_Other> *)(this); }
    template <class _Other> operator const const_reverse_iterator<_Other> () const { return *(const const_reverse_iterator<_Other> *)(this); }
    operator iterator<_Ty> () { return current; }
    operator const iterator<_Ty> () const { return current; }

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Knut HunstadCommented:
I am looking at VS2005, but can't quite see how this would compile there, even though you say it did?? Well, I throw in my 2c anyway...

The documentation says that std::iterator needs at least two arguments, Category and Type:

template<class Category, class Type, class Distance = ptrdiff_t,    class Pointer = Type*, class Reference = Type&>
struct iterator {

Could you show what you did when you said you tried to add another parameter to the iterator?

Just to be sure: you _do_ mean std::iterator<_Ty> and not some iterator<_Ty> from your own class?
KelarosAuthor Commented:
It definitely compiles in VS2005, and we have been using it for awhile.  

The iterator is from our own class but it is derived from std::iterator, like so:
template <class _Ty>
class const_iterator : public std::iterator<std::random_access_iterator_tag, _Ty, CBuffer::difference_type>

template <class _Ty>
  class iterator : public const_iterator<_Ty>

If I try to add any other parameters, like:
iterator<0, _Ty>
Or adding the _Category class,
iterator<_Category, _Ty>
Now I get a "too many arguments" error.
Knut HunstadCommented:
Not sure I'm really giving expert advice here, but if I where you, I'd try including the namespace of your class where you have "iterator<_Ty>" in your reverse_iterator class. This to eliminate the possibility of the compiler trying to match this with std::iterator.

Also in your definition of iterator, try to include:

template <class _Ty>
  class iterator : public OurNamespace::const_iterator<_Ty>

to again make sure the compiler isn't trying to match this to std::const_iterator.

In the "too many arguments" message, is the compiler still referring to std::iterator?

If this does the trick, I would expect that you somehow have introduced a "using namespace std" without really meaning to do so.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KelarosAuthor Commented:
Namespace was the problem.  I included our namespace and everything worked. Thanks!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.