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

Posted on 2008-11-13
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
    LVL 8

    Expert Comment

    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?
    LVL 5

    Author Comment

    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.
    LVL 8

    Accepted Solution

    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.
    LVL 5

    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now