vendredi 20 septembre 2019

How to determine which function to call?

i use “std::sort” to sort the vector,as we know, std::sort will call the funtion "_DEBUG_RANGE"(finally call the "_Debug_range2") to check the iterator. code:

template<class _RanIt> inline
    void _Debug_range2(_RanIt _First, _RanIt _Last,
        _Dbfile_t _File, _Dbline_t _Line, random_access_iterator_tag)
    {   // test iterator pair for valid range, random-access iterators
    if (_First != _Last)
        {   // check for non-null pointers, valid range
        _DEBUG_POINTER2(_First, _File, _Line);
        _DEBUG_POINTER2(_Last, _File, _Line);
        if (_Last < _First)
            _DEBUG_ERROR2("invalid iterator range", _File, _Line);
        }
    }

The error occurred in “if (_Last < _First)”,usually, "operator< (T &r)" is called, but i must use the 3rd libaray(fastdb),the 3rd libaray has the function "bool operator<(T& t1. T& t2)",“if (_Last < _First)” call the last one,but i want to call the first one. Now i do not know how to do...

//first operator< , i want to call
bool operator< (T &r)
{
   return this._ptr < r.ptr;
}

//second , defined in 3rd library
template<class T>
inline bool operator < (T const& x, T const& y)
{ 
    return memcmp(&x, &y, sizeof(T)) < 0;
}

Aucun commentaire:

Enregistrer un commentaire