all groups > visual c libraries > october 2005 >
You're in the

visual c libraries

group:

reverse_iterator in const member functions C2784 compiler error


reverse_iterator in const member functions C2784 compiler error qwerty2_reverse_iterator
10/15/2005 10:42:02 PM
visual c libraries:
Compiler version: 7.1.3088

Is this a bug in the compiler:

If I use a reverse_iterator as an operand to the != operator in a const
member function of a class I get a compiler error. However, if I assign that
reverse_iterator to a const_reverse_iterator and then use the
const_reverse_iterator as an operand to the != operator then I don't get any
compiler errors. Yet they both do the same thing. Here is the code snippet
that reproduces the problem:

#include <list>

class Qwerty2
{
public:
void foo() const
{
//---------------------------------------------
//Causes compiler errors.
//---------------------------------------------
if( m_ReverseIter != list1.rend() ) { }

//---------------------------------------------
//Does not cause compiler errors but does the same thing.
//---------------------------------------------
//IntList::const_reverse_iterator rItCurrent = m_ReverseIter;
//if( rItCurrent != list1.rend() ) { }

//Same thing as above, this works too.
//if( (IntList::const_reverse_iterator)m_ReverseIter != list1.rend() ) { }

}

private:
typedef std::list<int> IntList;
IntList list1;
IntList::reverse_iterator m_ReverseIter;
};


Here is a sample of the errors I get:

Compiling...
T2.cpp
T2.cpp(11) : error C2784: 'bool std::operator !=(const std::list<_Ty,_Alloc>
&,const std::list<_Ty,_Alloc> &)' : could not deduce template argument for
'const std::list<_Ty,_Ax> &' from 'const std::list<_Ty>::reverse_iterator'
with
[
_Ty=int
]
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\list(984) : see declaration of 'std::operator`!=''

T2.cpp(11) : error C2676: binary '!=' : 'const
std::list<_Ty>::reverse_iterator' does not define this operator or a
conversion to a type acceptable to the predefined operator
with
[
_Ty=int
Re: reverse_iterator in const member functions C2784 compiler error Bo Persson
10/16/2005 9:47:09 AM

"qwerty2_reverse_iterator"
<qwerty2_reverse_iterator@discussions.microsoft.com> skrev i
meddelandet news:2BBBC080-4B60-44A8-8E22-3A06E36809AF@microsoft.com...
[quoted text, click to view]

No, not really.

[quoted text, click to view]

There are suggestions to add this to a future revision of the
language, but it is not yet a requirement in the Standard.

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#280

This issue has status Ready, meaning that it is ready for a vote by
the standards committee, but that hasn't happened yet.


Bo Persson

Re: reverse_iterator in const member functions C2784 compiler erro qwerty2_reverse_iterator
10/16/2005 3:25:03 PM
Thanks!

[quoted text, click to view]
AddThis Social Bookmark Button