I am trying to compile a small dll COM library (using visual studio 2008 pro) and it compiles fine in the version, but when I try to compile it in debug, I get a compilation error:
error C2664: 'bool (MyClass &, double)': cannot convert parameter 2 from "MyClass" to "double".
Now this error comes from a line in the code where I do this (note that someValueThatIsADouble is of type double):
std::vector<MyClass>::iterator iter = std::lower_bound(MyVector.begin(), MyVector.end(), someValueThatIsADouble, less);
And the smaller the function is defined this way:
bool less(MyClass& a, double b);
I donβt understand why I get this error, and if there is a good reason for this error, why do I only get it in Debug (and not in Release)? The DLL, when compiled in Release, works fine and does not crash. Also, I checked and #ifdef DEBUG or such things that could change the code that was compiled in debug and release do not exist.
EDIT:
I myself did not write the code, and this is an algorithm that I know little about, so I donβt know what should represent a double value, and I do not want to change the logic inside less to use MyClass instead of double as the second parameter.
class MyClass { public : MyClass(): _dValue1(0.0),_dValue2(0.0),_dValue3(0.0) { } MyClass(double dValue1, double dValue3, double dValue2): _dValue2(dValue2),_dValue3(dValue3),_dValue1(dValue1) { } ~MyClass() {} double getValue1() {return _dValue1;} double getValue3() {return _dValue3;} double getValue2() {return _dValue2;} double _dValue1; double _dValue3; double _dValue2; public: friend class vector<MyClass>; int compare(const MyClass & t1, const MyClass & t2) { if (t1._dValue1 < t2._dValue1) return -1; else if (t2._dValue1 < t1._dValue1) return 1; else return 0; } bool operator> (const MyClass & rhs) { if ( _dValue1 > rhs._dValue1) return true; else return false; } bool operator< (const MyClass & rhs) { if ( _dValue1 < rhs._dValue1) return true; else return false; } };
Edit:
MSalters answer showed that the implementations of the predicates for debugging and release were not the same, which made it compile in the release, and not in debugging in my case (because the code is not very neat and should not use a comparison function with 2 different types). The hack I did to use this code in debugging was also to put this line before any inclusions (note that the preferred solution should be to have a better comparison function, but in my case it was not possible ):
#define _HAS_ITERATOR_DEBUGGING 0