简体   繁体   English

在STL中使用比较算法

[英]Using compare algorithm in STL

I am reading about algorithms at following location. 我正在以下位置阅读有关算法的信息。

http://www.brpreiss.com/books/opus4/html/page116.html http://www.brpreiss.com/books/opus4/html/page116.html

Here it is mentioned as below 这里提到如下

template <class T>
int Wrapper<T>::CompareTo (Object const& obj) const
{
    Wrapper<T> const& arg =
    dynamic_cast<Wrapper<T> const&> (obj);
    return ::Compare (datum, arg.datum);
}

The CompareTo member function is implemented in the same way as the Hash member function. CompareTo成员函数的实现方式与Hash成员函数相同。 Ie, it calls the global (non-member) function ::Compare to do the actual comparison. 即,它调用全局(非成员)函数::Compare进行实际比较。

My question; 我的问题; what does author mean by global compare function in C++? 作者在C ++中的全局比较功能是什么意思? Do we have to include any header file here as code is not compiling? 由于代码未编译,我们是否必须在此处包括任何头文件?

As one of the comment mentioned above here in this context Compare is nothing to do with STL. 正如在此上下文中上面提到的评论之一,Compare与STL无关。 I missed the last sentence on the page: "The implementation of a suitable compare function is left as a project for the reader" 我错过了页面上的最后一句话:“适当的比较功能的实现留给了读者一个项目”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM