c++ - 模板定义的基础问题
巴扎黑
巴扎黑 2017-04-17 13:08:27
0
1
497
template <typename T>int compare(const T &v1, const T &v2)
{
    if (less<T>()(v1, v2)) return -1;//这里的less<T>后面为什么有两对括号?第一对为何是空的?
}
巴扎黑
巴扎黑

reply all(1)
左手右手慢动作

less is a function object. The so-called function object is a class that overloads the call operator (that is, the "()" operator). Its object can be "used like a function", so it is called a function object. First A bracket indicates calling the constructor, and the following brackets are its parameters. This should be an example on C++ Primer. For details, please see the introduction to the function call operator on page 506 of C++ Primer 5th.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template