1
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を呼び出します。compComp

4

1 に答える 1