Created
February 2, 2014 19:01
-
-
Save kreshikhin/8773081 to your computer and use it in GitHub Desktop.
functor with pimpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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