Binary Predicate for Templated Class
-
I created a binary predicate // binary predicate for searching by exp date bool exp_LT(curvePoint lhs, curvePoint rhs) { return (lhs.getExp() < rhs.getExp()); } so I could search a vector by _expDate rather than _mDate on the curvePoint class: template class curvePoint : public subscriber { friend fwdCurve; friend bktCurve; public: void setValue(_Ty p) { _mValue = p; } _Ty getValue() { return _mValue; } void setDate(Date d) { _mDate = d; } inline void setDate(long d) { _mDate = d; } Date getDate() { return _mDate; } void setExp(Date d) { _expDate = d; } void setExp(long d) { _expDate = d; } Date getExp() { return _expDate; } void update() {} // allow self comparison bool operator<(const curvePoint<_Ty>& rhs) const { return _mDate < rhs._mDate; } bool operator>(const curvePoint<_Ty>& rhs) const { return _mDate > rhs._mDate; } bool operator==(const curvePoint<_Ty>& rhs) const { return _mDate == rhs._mDate; } bool operator!=(const curvePoint<_Ty>& rhs) const { return _mDate != rhs._mDate; } protected: _Ty _mValue; Date _mDate; Date _expDate; }; When I call curvePoint c; c.setExp(myDate("01/01/2009")); i = lower_bound(vector.begin(), vector.end(), &c, exp_LT); <---- Crashes here The compiler throws an error (C2664). The message is 1>c:\program files\microsoft visual studio 8\vc\include\xutility(312) : error C2664: 'bool (RAIV::curvePoint<_Ty>,RAIV::curvePoint<_Ty>)' : cannot convert parameter 2 from 'RAIV::curvePoint<_Ty> ' to 'RAIV::curvePoint<_Ty>' 1> with 1> [ 1> _Ty=double 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous I'm guessing the compiler cannot resolve something about the templated curvePoint parameter but am at a loss as to how to proceed.
-
I created a binary predicate // binary predicate for searching by exp date bool exp_LT(curvePoint lhs, curvePoint rhs) { return (lhs.getExp() < rhs.getExp()); } so I could search a vector by _expDate rather than _mDate on the curvePoint class: template class curvePoint : public subscriber { friend fwdCurve; friend bktCurve; public: void setValue(_Ty p) { _mValue = p; } _Ty getValue() { return _mValue; } void setDate(Date d) { _mDate = d; } inline void setDate(long d) { _mDate = d; } Date getDate() { return _mDate; } void setExp(Date d) { _expDate = d; } void setExp(long d) { _expDate = d; } Date getExp() { return _expDate; } void update() {} // allow self comparison bool operator<(const curvePoint<_Ty>& rhs) const { return _mDate < rhs._mDate; } bool operator>(const curvePoint<_Ty>& rhs) const { return _mDate > rhs._mDate; } bool operator==(const curvePoint<_Ty>& rhs) const { return _mDate == rhs._mDate; } bool operator!=(const curvePoint<_Ty>& rhs) const { return _mDate != rhs._mDate; } protected: _Ty _mValue; Date _mDate; Date _expDate; }; When I call curvePoint c; c.setExp(myDate("01/01/2009")); i = lower_bound(vector.begin(), vector.end(), &c, exp_LT); <---- Crashes here The compiler throws an error (C2664). The message is 1>c:\program files\microsoft visual studio 8\vc\include\xutility(312) : error C2664: 'bool (RAIV::curvePoint<_Ty>,RAIV::curvePoint<_Ty>)' : cannot convert parameter 2 from 'RAIV::curvePoint<_Ty> ' to 'RAIV::curvePoint<_Ty>' 1> with 1> [ 1> _Ty=double 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous I'm guessing the compiler cannot resolve something about the templated curvePoint parameter but am at a loss as to how to proceed.
-
I created a binary predicate // binary predicate for searching by exp date bool exp_LT(curvePoint lhs, curvePoint rhs) { return (lhs.getExp() < rhs.getExp()); } so I could search a vector by _expDate rather than _mDate on the curvePoint class: template class curvePoint : public subscriber { friend fwdCurve; friend bktCurve; public: void setValue(_Ty p) { _mValue = p; } _Ty getValue() { return _mValue; } void setDate(Date d) { _mDate = d; } inline void setDate(long d) { _mDate = d; } Date getDate() { return _mDate; } void setExp(Date d) { _expDate = d; } void setExp(long d) { _expDate = d; } Date getExp() { return _expDate; } void update() {} // allow self comparison bool operator<(const curvePoint<_Ty>& rhs) const { return _mDate < rhs._mDate; } bool operator>(const curvePoint<_Ty>& rhs) const { return _mDate > rhs._mDate; } bool operator==(const curvePoint<_Ty>& rhs) const { return _mDate == rhs._mDate; } bool operator!=(const curvePoint<_Ty>& rhs) const { return _mDate != rhs._mDate; } protected: _Ty _mValue; Date _mDate; Date _expDate; }; When I call curvePoint c; c.setExp(myDate("01/01/2009")); i = lower_bound(vector.begin(), vector.end(), &c, exp_LT); <---- Crashes here The compiler throws an error (C2664). The message is 1>c:\program files\microsoft visual studio 8\vc\include\xutility(312) : error C2664: 'bool (RAIV::curvePoint<_Ty>,RAIV::curvePoint<_Ty>)' : cannot convert parameter 2 from 'RAIV::curvePoint<_Ty> ' to 'RAIV::curvePoint<_Ty>' 1> with 1> [ 1> _Ty=double 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous I'm guessing the compiler cannot resolve something about the templated curvePoint parameter but am at a loss as to how to proceed.
-
I created a binary predicate // binary predicate for searching by exp date bool exp_LT(curvePoint lhs, curvePoint rhs) { return (lhs.getExp() < rhs.getExp()); } so I could search a vector by _expDate rather than _mDate on the curvePoint class: template class curvePoint : public subscriber { friend fwdCurve; friend bktCurve; public: void setValue(_Ty p) { _mValue = p; } _Ty getValue() { return _mValue; } void setDate(Date d) { _mDate = d; } inline void setDate(long d) { _mDate = d; } Date getDate() { return _mDate; } void setExp(Date d) { _expDate = d; } void setExp(long d) { _expDate = d; } Date getExp() { return _expDate; } void update() {} // allow self comparison bool operator<(const curvePoint<_Ty>& rhs) const { return _mDate < rhs._mDate; } bool operator>(const curvePoint<_Ty>& rhs) const { return _mDate > rhs._mDate; } bool operator==(const curvePoint<_Ty>& rhs) const { return _mDate == rhs._mDate; } bool operator!=(const curvePoint<_Ty>& rhs) const { return _mDate != rhs._mDate; } protected: _Ty _mValue; Date _mDate; Date _expDate; }; When I call curvePoint c; c.setExp(myDate("01/01/2009")); i = lower_bound(vector.begin(), vector.end(), &c, exp_LT); <---- Crashes here The compiler throws an error (C2664). The message is 1>c:\program files\microsoft visual studio 8\vc\include\xutility(312) : error C2664: 'bool (RAIV::curvePoint<_Ty>,RAIV::curvePoint<_Ty>)' : cannot convert parameter 2 from 'RAIV::curvePoint<_Ty> ' to 'RAIV::curvePoint<_Ty>' 1> with 1> [ 1> _Ty=double 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous I'm guessing the compiler cannot resolve something about the templated curvePoint parameter but am at a loss as to how to proceed.
It turned out that I called the routine correctly 5 times, on the sixth call, I had the wrong kind of parameter there, (an iterator as opposed to the actual class). Somehow that caused an error in all six places the function was called.
-
I created a binary predicate // binary predicate for searching by exp date bool exp_LT(curvePoint lhs, curvePoint rhs) { return (lhs.getExp() < rhs.getExp()); } so I could search a vector by _expDate rather than _mDate on the curvePoint class: template class curvePoint : public subscriber { friend fwdCurve; friend bktCurve; public: void setValue(_Ty p) { _mValue = p; } _Ty getValue() { return _mValue; } void setDate(Date d) { _mDate = d; } inline void setDate(long d) { _mDate = d; } Date getDate() { return _mDate; } void setExp(Date d) { _expDate = d; } void setExp(long d) { _expDate = d; } Date getExp() { return _expDate; } void update() {} // allow self comparison bool operator<(const curvePoint<_Ty>& rhs) const { return _mDate < rhs._mDate; } bool operator>(const curvePoint<_Ty>& rhs) const { return _mDate > rhs._mDate; } bool operator==(const curvePoint<_Ty>& rhs) const { return _mDate == rhs._mDate; } bool operator!=(const curvePoint<_Ty>& rhs) const { return _mDate != rhs._mDate; } protected: _Ty _mValue; Date _mDate; Date _expDate; }; When I call curvePoint c; c.setExp(myDate("01/01/2009")); i = lower_bound(vector.begin(), vector.end(), &c, exp_LT); <---- Crashes here The compiler throws an error (C2664). The message is 1>c:\program files\microsoft visual studio 8\vc\include\xutility(312) : error C2664: 'bool (RAIV::curvePoint<_Ty>,RAIV::curvePoint<_Ty>)' : cannot convert parameter 2 from 'RAIV::curvePoint<_Ty> ' to 'RAIV::curvePoint<_Ty>' 1> with 1> [ 1> _Ty=double 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous I'm guessing the compiler cannot resolve something about the templated curvePoint parameter but am at a loss as to how to proceed.
On a side note, a few changes will makes things better. First change this function by adding the underlined bits:
bool exp_LT(const curvePoint<double> &lhs, const curvePoint<double> &rhs) { return (lhs.getExp() < rhs.getExp()); }
Now change the class as follows (again, by adding the underlined bits):
public:
void setValue(_Ty p) { _mValue = p; }
_Ty getValue() const { return _mValue; }
void setDate(Date d) { _mDate = d; }
inline void setDate(long d) { _mDate = d; }
Date getDate() const { return _mDate; }
void setExp(Date d) { _expDate = d; }
void setExp(long d) { _expDate = d; }
Date getExp() const { return _expDate; }Steve