Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C++ Libraries / October 2005

Tip: Looking for answers? Try searching our database.

reverse_iterator in const member functions C2784 compiler error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
qwerty2_reverse_iterator - 16 Oct 2005 06:42 GMT
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
       ]
Bo Persson - 16 Oct 2005 08:47 GMT
> Compiler version: 7.1.3088
>
> Is this a bug in the compiler:

No, not really.

> If I use a reverse_iterator as an operand to the != operator in a
> const
[quoted text clipped - 4 lines]
> get any
> compiler errors.  Yet they both do the same thing.

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
qwerty2_reverse_iterator - 16 Oct 2005 23:25 GMT
Thanks!

> > Compiler version: 7.1.3088
> >
[quoted text clipped - 20 lines]
>
> Bo Persson

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.