#include <iostream>
#include <deque>

struct Foo {
    bool memberFunc() { std::cout << "memberFunc of Foo called." << std::endl; return true; }
};

struct Bar {
    bool memberFunc() { std::cout << "memberFunc of Bar called." << std::endl; return true; }
};

struct func_base {
    virtual ~func_base() {};
    virtual bool operator()() const = 0;
};

template <typename C>
class func_wrapper : public func_base {
public:
    typedef bool (C::*member_func_ptr_t)();
    func_wrapper(member_func_ptr_t func_ptr, C* instance_ptr) : m_func_ptr(func_ptr), m_instance_ptr(instance_ptr) {}
    bool operator()() const { return (m_instance_ptr->*m_func_ptr)(); }
private:
    member_func_ptr_t m_func_ptr;
    C* m_instance_ptr;
};

/* This function returns a pointer to dynamically *
 * allocated memory and it is thus the callers    *
 * responsibility to deallocate the memory!!      */
template <typename C>
func_base* make_wrapper(bool (C::*func_ptr)(), C* instance_ptr) {
    return new func_wrapper<C>(func_ptr, instance_ptr);
}

int main() {
    Foo foo;
    Bar bar;

    std::deque<func_base*> d;

    d.push_back(make_wrapper(&Foo::memberFunc, &foo));
    d.push_back(make_wrapper(&Bar::memberFunc, &bar));

    for (std::deque<func_base*>::iterator it = d.begin(); it != d.end(); ++it) {
        (**it)();
    }

    for (std::deque<func_base*>::iterator it = d.begin(); it != d.end(); ++it) {
        delete *it;
    }
}