operator overload question
ok here's another one:
I get these errors when compiling my code
1>c:\programme\microsoft visual studio 8\vc\include\xutility(256) :
error C2666: 'eoScalarFitness<ScalarType,Compare>::operator <' : 2
overloads have similar conversions
1> with
1> [
1> ScalarType=double,
1> Compare=std::greater<double>
1> ]
1> cvs-eo\eo\src\eoscalarfitness.h(59): could be 'bool
eoScalarFitness<ScalarType,Compare>::operator <(const
eoScalarFitness<ScalarType,Compare> &) const'
1> with
1> [
1> ScalarType=double,
1> Compare=std::greater<double>
1> ]
1> or 'built-in C++ operator<(double, double)'
1> while trying to match the argument list
'(eoScalarFitness<ScalarType,Compare>, const double)'
1> with
1> [
1> ScalarType=double,
1> Compare=std::greater<double>
1> ]
1> c:\programme\microsoft visual studio
8\vc\include\algorithm(2063) : see reference to function template
instantiation 'bool
std::_Debug_lt<_Ty,eoScalarFitness<ScalarType,Compare>>(const _Ty1
&,_Ty2 &,const wchar_t *,unsigned int)' being compiled
1> with
1> [
1> _Ty=double,
1> ScalarType=double,
1> Compare=std::greater<double>,
1> _Ty1=double,
1> _Ty2=eoScalarFitness<double,std::greater<double>>
1> ]
1> c:\programme\microsoft visual studio
8\vc\include\algorithm(2075) : see reference to function template
instantiation '_FwdIt
std::_Upper_bound<std::_Vector_iterator<_Ty,_Alloc>,double,__w64
int>(_FwdIt,_FwdIt,const double &,_Diff *)' being compiled
1> with
1> [
1>
_FwdIt=std::_Vector_iterator<eoMinimizingFitness,std::allocator<eoMinimizingFitness>>,
1> _Ty=eoMinimizingFitness,
1> _Alloc=std::allocator<eoMinimizingFitness>,
1> _Diff=__w64 int
1> ]
1> cvs-eo\eo\src\eoproportionalselect.h(75) : see reference to
function template instantiation '_FwdIt
std::upper_bound<std::_Vector_iterator<_Ty,_Alloc>,double>(_FwdIt,_FwdIt,const
double &)' being compiled
1> with
1> [
1>
_FwdIt=std::_Vector_iterator<eoMinimizingFitness,std::allocator<eoMinimizingFitness>>,
1> _Ty=eoMinimizingFitness,
1> _Alloc=std::allocator<eoMinimizingFitness>
1> ]
1> cvs-eo\eo\src\eoproportionalselect.h(71) : while compiling
class template member function 'const eoBit<FitT>
&eoProportionalSelect<EOT>::operator ()(const eoPop<EOT> &)'
1> with
1> [
1> FitT=eoMinimizingFitness,
1> EOT=eoBit<eoMinimizingFitness>
1> ]
1> cvs-eo\eo\src\do\make_algo_scalar.h(200) : see reference to
class template instantiation 'eoProportionalSelect<EOT>' being compiled
1> with
1> [
1> EOT=eoBit<eoMinimizingFitness>
1> ]
1> cvs-eo\eo\src\ga\make_algo_scalar_ga.cpp(60) : see reference
to function template instantiation 'eoAlgo<EOT>
&do_make_algo_scalar<eoBit<FitT>>(eoParser &,eoState &,eoEvalFunc<EOT>
&,eoContinue<EOT> &,eoGenOp<EOT> &,eoDistance<EOT> *)' being compiled
1> with
1> [
1> EOT=eoBit<eoMinimizingFitness>,
1> FitT=eoMinimizingFitness
1> ]
the code in xutility is
template<class _Ty1, class _Ty2> inline
bool __CLRCALL_OR_CDECL _Debug_lt(const _Ty1& _Left, _Ty2& _Right,
const wchar_t *_Where, unsigned int _Line)
{ // test if _Left < _Right and operator< is strict weak ordering
if (!(_Left < _Right))
return (false);
else if (_Right < _Left) // LINE 256
_DEBUG_ERROR2("invalid operator<", _Where, _Line);
return (true);
}
There is an operator overload defined
template <class ScalarType, class Compare >
class eoScalarFitness
{
public :
eoScalarFitness() : value() {}
eoScalarFitness(const eoScalarFitness& other) : value(other.value) {}
eoScalarFitness(const ScalarType& v) : value(v) {}
eoScalarFitness& operator=(const eoScalarFitness& other)
{ value = other.value; return *this; }
eoScalarFitness& operator=(const ScalarType& v)
{ value = v; return *this; }
operator ScalarType(void) const { return value; }
/// Comparison, using less by default
bool operator<( const eoScalarFitness & other) const { return
Compare()(value, other.value); } // THIS IS THE FAULTY? OVERLOAD
// implementation of the other operators
bool operator>( const eoScalarFitness<ScalarType, Compare>& y )
const { return y < *this; }
// implementation of the other operators
bool operator<=( const eoScalarFitness<ScalarType, Compare>& y )
const { return !(*this > y); }
// implementation of the other operators
bool operator>=(const eoScalarFitness<ScalarType, Compare>& y )
const { return !(*this < y); }
private :
ScalarType value;
};
-> How can I force msvc to use overload in order to end it's confusion
about which one to use?
cheers, Oliver