仿函数示例

template<typename ReturnType, typename OutterType, typename ArgType>
struct UnaryOperator
{
 private:
       OutterType& outter;
       ReturnType(OutterType* method)(ArgType);

public:
      UnaryOperator(OutterType &outter, ReturnType(OutterType::* method)(ArgType)) : outter(outter), method(method)
      {
      }

      ReturnType operator()(ArgType arg)
      {
            return (outter.*method)( arg );
      }
}

//用法:

MyClass myClass;

GetFiles(TEXT("C:\\"), UnaryOperator<BOOL, MyClass, const String&>(myClass, &(MyClass::addFilePath2Arr)));

posted on 2007-09-28 14:41  李超  阅读(185)  评论(0编辑  收藏  举报

导航