none
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'RX::FastSet<BASE>::sortedAppender' (or

    Question

  • The problem occurs in Visual Studio 2005 but works in Vc++6.0

    rx_fastset.h

    struct SortedAppender

    {

     

    typedef Std:: output_iterator_tag iterator_category;

    typedef BASE value_type;

    typedef ptrdiff_t difference_type;

    typedef BASE* pointer;

    typedef BASE& reference;

    sortedAppender(FastSet& fastSet): m_fastSet(fastSet) {}

    sortedAppender& operator=(value_type v) { m_fastSet.sortedAppend(v); return *this;}

    sortedAppender& operator*() { return *this; }

    sortedAppender& operator++() { return *this; }

    sortedAppender& operator++(int) { return *this; }

    FastSet& m_fastSet;

    };

     

    rx_vist.cpp

     

    inline

    void SetUnion(const NodeIdSet& leftSet, const NodeIdSet& rightSet, NodeIdSet& unionSet)

    {

    assert(unionSet.empty());

    std:: set_union(leftSet.begin(), leftSet.end(),

    rightSet.begin(), rightSet.end(),

    NodeIdSet:: sortedAppender(unionSet));

    }

     

    I am getting the following errors..

     

    rx_vist.cpp

    c:\program files\microsoft visual studio 8\vc\include\algorithm(3815) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'RX:: FastSet<BASE>:: sortedAppender' (or there is no acceptable conversion)

    with

    [

    BASE=RX::NodeId

    ]

    c:\a\rx_fastset.h(63): could be 'RX::FastSet<BASE>:: sortedAppender &RX:: FastSet<BASE>:: sortedAppender:: operator =(unsigned int)'

    with

    [

    BASE=RX::NodeId

    ]

    while trying to match the argument list '(RX::FastSet<BASE>:: sortedAppender, RX::FastSet<BASE>:: sortedAppender)'

    with

    [

    BASE=RX::NodeId

    ]

    c:\program files\microsoft visual studio 8\vc\include\algorithm(3850) : see reference to function template instantiation '_OutIt std:: _Set_union<std:: _Vector_const_iterator<_Ty,_Alloc>,std::_Vector_const_iterator<_Ty,_Alloc>,_OutIt>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt,std::_Range_checked_iterator_tag)' being compiled

    with

    [

    _OutIt=RX::FastSet<RX::NodeId>:: sortedAppender,

    _Ty=RX::NodeId,

    _Alloc=std::allocator<RX::NodeId>,

    _InIt1=std::_Vector_const_iterator<RX::NodeId,std::allocator<RX::NodeId>>,

    _InIt2=std::_Vector_const_iterator<RX::NodeId,std::allocator<RX::NodeId>>

    ]

    c:\a\rx_vist.cpp(77) : see reference to function template instantiation 'RX::FastSet<BASE>:: sortedAppender std:Tongue Tiedet_union<std::_Vector_const_iterator<_Ty,_Alloc>,std::_Vector_const_iterator<_Ty,_Alloc>,RX::FastSet<BASE>:: sortedAppender>(_InIt1,_InIt1,_InIt2,_InIt2,_OutIt)' being compiled

    with

    [

    BASE=RX::NodeId,

    _Ty=RX::NodeId,

    _Alloc=std::allocator<RX::NodeId>,

    _InIt1=std::_Vector_const_iterator<RX::NodeId,std::allocator<RX::NodeId>>,

    _InIt2=std::_Vector_const_iterator<RX::NodeId,std::allocator<RX::NodeId>>,

    _OutIt=RX::FastSet<RX::NodeId>:: sortedAppender

    ]

    c:\program files\microsoft visual studio 8\vc\include\algorithm(3815) : error C2582: 'operator =' function is unavailable in 'RX::FastSet<BASE>:: sortedAppender'

    with

    [

    BASE=RX::NodeId

    ]

     

    Any help in this would be grateful.

    Monday, April 09, 2007 4:51 PM

Answers

  • There still isn't enough information here to be able to say for certain what is going. With Visual C++ 6.0 the compiler was not as conformant and the C++ library allowed stuff that it shouldn't - so there could be many reasons why this doesn't compile - but I would look at const-correctnes and implicit conversion of iterators to pointer - both of which were issues with the Visual C++ 6.0 implementation.
    Monday, April 09, 2007 8:54 PM
    Moderator
  • To me the error message suggests that SortedAppender is not a valid output iterator. Specifically, it is not assignable as required by the standard. Also, it is very odd design to return the object itself from operator* rather a proxy or a reference to a member should be returned. In your case the iterator acts as value_type proxy as well. That is poor design.

     

    Anyway, you will probably need to implement operator=( const SortedAppender&) and for that to work you'll probably have to make the m_fastSet a pointer as a reference can't rebind.

     

    edit: Oh, I didn't bother to look carefully enough, but when you use a pointer for m_fastSet the compiler can generate the copy-assignment operator for you with the appropriate semantics.

     

    -hg

    Friday, April 13, 2007 7:40 PM

All replies

  • There isn't really enough to go on here but I suspect that the signature of the operator= might need to be

     

    sortedAppender& operator=(const value_type& v) { m_fastSet.sortedAppend(v); return *this;}

    Monday, April 09, 2007 7:08 PM
    Moderator
  • Jonathan:

    Let me Explain Clearly. This is the part of the Code where the error Happens


    inline
        void SetUnion(const NodeIdSet& leftSet, const NodeIdSet& rightSet, NodeIdSet& unionSet)
        {
            assert(unionSet.empty());
      std:Tongue Tiedet_union(leftSet.begin(), leftSet.end(),
                           rightSet.begin(), rightSet.end(),
           NodeIdSet:Tongue TiedortedAppender(unionSet));
        }

     

    if I comment this part of the code, it compiles.

     

    /*  std:Tongue Tiedet_union(leftSet.begin(), leftSet.end(),
                           rightSet.begin(), rightSet.end(),
           NodeIdSet:Tongue TiedortedAppender(unionSet));

    */

     

    There is a problem here and Error is described previously.

     

    Let me give you the exact class definitions

     

    namespace RX
    {
        template <class BASE>
        class FastSet
        {
        private:
            typedef std::vector<BASE>                  SetType;

        public:
            typedef typename SetType::iterator         iterator;
            typedef typename SetType::const_iterator   const_iterator;
            typedef typename SetType::const_reference  const_reference;
            typedef typename SetType::value_type       value_type;

            FastSet() {}
            FastSet(const FastSet& original): m_set(original.m_set) {}
            FastSet(const SetType& original): m_set(original) {}

            void clear();

            bool empty() const;

            size_t size() const;
           
            size_t max_size() const;
           
            void sortedAppend(value_type);
            void unique();

            void swap(FastSet& fastSet);

            iterator begin();
            iterator end();

            const BASE& operator[](unsigned) const;
           
            const_iterator begin() const;
            const_iterator end() const;

            static bool less(const FastSet& leftSet, const FastSet& rightSet);
            static bool equal(const FastSet& leftSet, const FastSet& rightSet);

        public:
            struct sortedAppender
            {
                // STL iterator preconditions
                typedef std:Surpriseutput_iterator_tag iterator_category;
                typedef BASE value_type;
                typedef ptrdiff_t difference_type;
                typedef BASE* pointer;
                typedef BASE& reference;

                sortedAppender(FastSet& fastSet): m_fastSet(fastSet) {}

                sortedAppender& operator=(value_type v) { m_fastSet.sortedAppend(v); return *this;}
                sortedAppender& operator*()             { return *this; }
                sortedAppender& operator++()            { return *this; }
                sortedAppender& operator++(int)         { return *this; }

                FastSet& m_fastSet;
            };

        private:
            SetType m_set;
        };

    } // end of namespace RX

    Monday, April 09, 2007 8:30 PM
  • There still isn't enough information here to be able to say for certain what is going. With Visual C++ 6.0 the compiler was not as conformant and the C++ library allowed stuff that it shouldn't - so there could be many reasons why this doesn't compile - but I would look at const-correctnes and implicit conversion of iterators to pointer - both of which were issues with the Visual C++ 6.0 implementation.
    Monday, April 09, 2007 8:54 PM
    Moderator
  • I will try and will let u know when its resolved.
    Friday, April 13, 2007 4:28 PM
  • To me the error message suggests that SortedAppender is not a valid output iterator. Specifically, it is not assignable as required by the standard. Also, it is very odd design to return the object itself from operator* rather a proxy or a reference to a member should be returned. In your case the iterator acts as value_type proxy as well. That is poor design.

     

    Anyway, you will probably need to implement operator=( const SortedAppender&) and for that to work you'll probably have to make the m_fastSet a pointer as a reference can't rebind.

     

    edit: Oh, I didn't bother to look carefully enough, but when you use a pointer for m_fastSet the compiler can generate the copy-assignment operator for you with the appropriate semantics.

     

    -hg

    Friday, April 13, 2007 7:40 PM