template <typename elemType, typename Comp = less<elemType> >
class LessThanPred {
public:
LessThanPred(const elemType &val) : _val(val){}
bool operator()(const elemType &val) const
{ return Comp(val, _val); }
void val(const elemType &newval) { _val = newval; }
elemType val() const { return _val; }
private:
elemType _val;};
これは、Essential c++ の例です。Comp
明らかに関数オブジェクトのクラス名です。Comp(val, _val)
を直接使用できるのはなぜですか? 通常は、最初に次のような関数オブジェクトを定義する必要があると思います: 、次にnotComp comp
を呼び出します。comp
Comp