std::list iterators not compiling with binary - or + in VC2005

    General discussion


    I have a class (say CXYZ), where I have declared the following in the header file.


    typedef std::list<CA*>::iterator Iter;
    std::list<CA*> m_Array;
    Iter m_CurIter;

    In the cpp file I have:

    void CXYZ::Func(CA* pA)

     unsigned idx = m_CurIter - m_Array.begin(); //LINE 1
     m_CurIter = m_Array.begin() + idx; //LINE 2


    For LINE1, these two errors are comming:

    error C2784: 'reverse_iterator<_RanIt>:Big Smileifference_type std:Surpriseperator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'CXYZ::Iter'
    error C2676: binary '-' : 'CXYZ::Iter' does not define this operator or a conversion to a type acceptable to the predefined operator


    For LINE2, this error is comming:

    error C2678: binary '+' : no operator found which takes a left-hand operand of type 'std::list<_Ty>::_Iterator<_Secure_validation>' (or there is no acceptable conversion)


    What is the problem?

    Are the std::list iterators not supposed to work with binary - and + operators?

    Tuesday, November 20, 2007 1:04 PM

All replies

  • Since this is a C++ langauge question, you might get better answers in the VC language forum. I think it is as easy to post there as it is to post here. If you now create a new thread in the other forum, it will be appreciated if you post a message here saying so.


    You con't show the definition of CA, and that is critical to providing an answer. If you create a new thread, be sure to show the definition of CA.


    I assume the compiler is saying it does not know how to do the things it is saying it does not know how to do. When the compiler says "does not define this operator or a conversion", I think it is saying it does not know how to do what you are saying to do. I think that is also meant by "no operator found which takes a left-hand operand of type".


    Note that your list consists of pointers to CA items, not CA items. Therefore the value of m_Array.begin() is a pointer, and I assume that is not what you intend. I assume you know C++ well enough to fix it; either change the value used for the list, or use indirection when needed.

    Wednesday, November 21, 2007 10:48 AM