I am not sure what you want to achieve so this may not be very helpful but here it is anyway.
As others have said you cannot create a std::vector for this as the prototypes are different. You can however create a std::tuple like this:
std::tuple<void (A::*)(), void (B::*)(), void (C::*)()> x(&A::aFoo, &B::bFoo, &C::c1Foo);
Assuming you have a an instance of a class, say A a
then you can call the function as in (a.*std::get<0>(x))()
.
If you have stored your objects in a tuple as well, then you can iterate over them. The following code will do just that (assumes you have C++14 and Boost in your system)
#include <iostream>
#include <tuple>
#include <type_traits>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/fusion/include/mpl.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <functional>
class A
{
public:
void aFoo()
{
std::cout << "A" << std::endl;
}
};
class B
{
public:
void bFoo()
{
std::cout << "B" << std::endl;
}
};
class C
{
public:
void c1Foo()
{
std::cout << "C1" << std::endl;
}
void c2Foo() {}
};
// functor used by boost to iterate over the tuple
template <class Tuple>
struct functor
{
functor(Tuple t)
: m_tuple(t)
{
}
template <class X>
void operator()(X& x) const
{
using namespace boost::mpl;
using iter = typename find_if<Tuple, std::is_same < placeholders::_1, void (X::*)()> >::type;
using type = typename deref<iter>::type;
return (x.*std::get<type>(m_tuple))();
}
private:
Tuple m_tuple;
};
template <class Tuple>
functor<Tuple> make_functor(Tuple t)
{
return functor<Tuple>(t);
}
int main()
{
std::tuple<void (A::*)(), void (B::*)(), void (C::*)() > x(&A::aFoo, &B::bFoo, &C::c1Foo);
std::tuple<A, B, C> y;
boost::fusion::for_each(y, make_functor(x));
}
Live demo here:
http://coliru.stacked-crooked.com/a/e840a75f5b42766b