• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2417
  • Last Modified:

"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

  • 2
  • 2
1 Solution
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.
KelarosAuthor Commented:
Namespace was the problem.  I included our namespace and everything worked. Thanks!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now