   cleaner functor class
  I'm writing my own functor class.  I have a working version of it now, but I'd like to make it cleaner.  Right now the class is templated with the return type ( the first version of this is for no parameters ) and the type of object whos member function will be called.  I think having to template with the object type is bad, I would like to only template this with the return type.Is it possible to remove that template argument?Could anyone give some ideas of how to do this?  Below is the void functor class as it is right now:#ifndef VOIDFUNCTOR_H#define VOIDFUNCTOR_Hnamespace Common{template <typename _classType, typename _ret>class VoidFunctor{public:VoidFunctor( _classType* obj, _ret(_classType::*meth)(void) ){m_obj = static_cast<void*>(obj);m_memFunc = meth;m_fnStatic = NULL;m_staticFunc = &(VoidFunctor<_classType, _ret>::CallOperator);}_ret operator()(void){(*m_staticFunc)(*this);}private:void*m_obj;_ret (_classType::*m_memFunc)(void);_ret (*m_fnStatic)(void);void (*m_staticFunc)(VoidFunctor<_classType, _ret>&);static _ret CallOperator(VoidFunctor<_classType, _ret>& func){if( func.m_obj ){return (reinterpret_cast<_classType*>(func.m_obj)->*(func.m_memFunc))();}else{return (func.m_fnStatic)();}}};}#endifHere is how my functors are created and how I'd like them to be created:   //How I have to declare a functor nowCommon::VoidFunctor<Player, void> fn( this, &Player::MoveShipRight);   //How I want to be able to declare oneCommon::VoidFunctor<void> fn( this, &Player::MoveShipRight);
Quote:Is it possible to remove that template argument?Not directly, though you can encapsulate the functor in another class that will hide the class type. It would store a pointer to a base functor class common to all VoidFunctors that have the same return type, and invoke a virtual function.template<class Result> struct BaseVoidFunctor{   virtual Result invoke() = 0;   virtual ~BaseVoidFunctor() = 0;};template<class Class, class Result>struct VoidFunctorImpl :   BaseVoidFunctor<Result>{   Class* obj;   Result (Class::*fn)();   virtual Result invoke() { return (obj->*fn)(); }   // more stuff};template<class Result>struct VoidFunctor{   BaseVoidFunctor<Result>* ptr;   Result operator()() { return ptr->invoke(); }   // more stuff (namely, dealing with the pointer)};Quote:Could anyone give some ideas of how to do this? Use template parameter deduction with a function, just list std::bind1st and others do.template <typename Class, typename Result>VoidFunctor<Class, Result> make_functor(Class* obj, Result (Class::*fn)() ){   return VoidFunctor<Class, Result>(obj, fn);}Or you could just use boost::bind (or simply boost::mem_fn) which does it all for you, and much more.   ;  Ahh... that's a good idea.  I'll start to play around with it.Thanks!   