Kelaros
asked on
"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.
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>
{
public:
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; }
};
ASKER
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_ite rator_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.
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_
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Namespace was the problem. I included our namespace and everything worked. Thanks!!!
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?