Überladener Operator erzeugt Fehler bei Verwendung von std :: map

class A
{
private:
    int a;
public:
    A( int set )
    {
        a = set;
    };
    ~A();
    bool operator <(const A& ref )
    {
        return this->a < ref.a;
    };
    bool operator ==(const A& ref )
    {
        return this->a == ref.a;
    };
};

int _tmain(int argc, _TCHAR* argv[])
{

    map<A,int>m;
    A a( 1 );
    m.insert( make_pair( a, 2 ) );
    for( map<A,int>::iterator it = m.begin(); it != m.end(); ++it )
    {

    }
    return 0;
}

Generiert C2678:http://msdn.microsoft.com/en-us/library/ys0bw32s(v=vs.80).aspx

für den Betreiber <

und wenn ich benutzem.find wird auch für den Betreiber generieren == Wie kommt man damit zurecht?

Genauer gesagt führt der Fehler zu:

template<class _Ty>
    struct less
        : public binary_function<_Ty, _Ty, bool>
    {   // functor for operator<
    bool operator()(const _Ty& _Left, const _Ty& _Right) const
        {   // apply operator< to operands
        return (_Left < _Right);
        }
    };

auf funktionale

Letzter Fall:

struct MASTERPLAYER
{
    int a;
    bool operator==( const MASTERPLAYER& ref ) const 
    {
        return a == ref.a;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{

    MASTERPLAYER m;
    vector<MASTERPLAYER>v;
    v.push_back( m );
    std::find( v.begin(), v.end(), 2 );

}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage