Перегруженный оператор выдает ошибки при использовании std :: map
class A
{
private:
int a;
public:
A( int set )
{
a = set;
};
~A();
bool operator a < ref.a;
};
bool operator ==(const A& ref )
{
return this->a == ref.a;
};
};
int _tmain(int argc, _TCHAR* argv[])
{
mapm;
A a( 1 );
m.insert( make_pair( a, 2 ) );
for( map::iterator it = m.begin(); it != m.end(); ++it )
{
}
return 0;
}
Создает C2678:http://msdn.microsoft.com/en-us/library/ys0bw32s(v=vs.80).aspx
для оператора <
и если я используюm.find
также сгенерирует для оператора == Как с этим обойтись?
Чтобы быть более конкретным, ошибка приводит к:
template
struct less
: public binary_function
{ // functor for operator< bool operator()(const _Ty& _Left, const _Ty& _Right) const
{ // apply operator< to operands
return (_Left < _Right);
}
};
по функционалу
Финальный случай:}
struct MASTERPLAYER
{
int a;
bool operator==( const MASTERPLAYER& ref ) const
{
return a == ref.a;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
MASTERPLAYER m;
vectorv;
v.push_back( m );
std::find( v.begin(), v.end(), 2 );