Skip to content

Instantly share code, notes, and snippets.

@kreshikhin
Created February 2, 2014 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreshikhin/8773081 to your computer and use it in GitHub Desktop.
Save kreshikhin/8773081 to your computer and use it in GitHub Desktop.
functor with pimpl
class AbstractFunctorImpl{public: virtual void Execute() = 0; };
template<class Object, class Method>
class FunctorImpl: public AbstractFunctorImpl{
Object obj;
Method meth;
public:
FunctorImpl(Object& obj, Method meth) : obj(obj), meth(meth) {}
void Execute(){ (obj.*meth)(); }
};
class Functor{
AbstractFunctorImpl* fctor;
public:
template<class Object, class Method>
Functor(Object obj, Method meth){
fctor = new FunctorImpl<Object, Method>(obj, meth);
}
void operator()(){ fctor->Execute(); };
~Functor(){ delete fctor; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment