Hello,
I have a bit of code that's giving me some trouble, but I can't make sense of the error. It boils down to an ambiguous call that I can't, for the life of me, figure out why is ambiguous.
Code then errors:
errors:Code:template<class numeric_type> struct diff_less_t { diff_less_t(numeric_type subtracted) : sub(subtracted) {} bool operator() ( const typename std::map<numeric_type, numeric_type>::value_type & a, const typename std::map<numeric_type, numeric_type>::value_type & b ) { return std::abs(a.first-sub) < std::abs(b.first-sub); } private: numeric_type sub; }; template<typename numeric_type> diff_less_t<numeric_type> diff_less(numeric_type sub) { return diff_less_t<numeric_type>(sub); } //. . . . quite a while later . . . //xmatch is a long double map<long double, long double>::iterator it = min_element(points.begin(), points.end(), diff_less(xmatch));
Thanks for any help.Code:extractpoints.cpp: In member function ‘bool diff_less_t<numeric_type>::operator()(const typename std::map<numeric_type, numeric_type, std::less<_Key>, std::allocator<std::pair<const numeric_type, numeric_type> > >::value_type&, const typename std::map<numeric_type, numeric_type, std::less<_Key>, std::allocator<std::pair<const numeric_type, numeric_type> > >::value_type&) [with numeric_type = long double]’: /usr/include/c++/4.2/bits/stl_algo.h:4974: instantiated from ‘_ForwardIterator std::min_element(_ForwardIterator, _ForwardIterator, _Compare) [with _ForwardIterator = std::_Rb_tree_iterator<std::pair<const long double, long double> >, _Compare = diff_less_t<long double>]’ extractpoints.cpp:66: instantiated from here extractpoints.cpp:16: error: call of overloaded ‘abs(long double)’ is ambiguous /usr/include/stdlib.h:691: note: candidates are: int abs(int) /usr/include/c++/4.2/cstdlib:143: note: long int std::abs(long int) /usr/include/c++/4.2/cstdlib:174: note: long long int __gnu_cxx::abs(long long int) extractpoints.cpp:16: error: call of overloaded ‘abs(long double)’ is ambiguous /usr/include/stdlib.h:691: note: candidates are: int abs(int) /usr/include/c++/4.2/cstdlib:143: note: long int std::abs(long int) /usr/include/c++/4.2/cstdlib:174: note: long long int __gnu_cxx::abs(long long int)



LinkBack URL
About LinkBacks



