[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2008-11-13
Medium Priority
Last Modified: 2013-12-14
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

Question by:Kelaros
  • 2
  • 2

Expert Comment

by:Knut Hunstad
ID: 22957818
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?

Author Comment

ID: 22960174
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.

Accepted Solution

Knut Hunstad earned 1200 total points
ID: 22961428
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.

Author Closing Comment

ID: 31516549
Namespace was the problem.  I included our namespace and everything worked. Thanks!!!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question