#include <iostream>
class Actions {
public:
Actions(){}
void doSmthg(){
std::cout<<"do something called"<<std::endl;
}
void multipleArgs(int, int)
{
std::cout<<"multiple int args called"<<std::endl;
}
};
class Entity
{
public:
void func(double)
{
std::cout<<"func called"<<std::endl;
}
};
template<typename T, typename Callable, typename... Args>
void exampleFunction(T obj, const Callable& callable, const Args&... args){
std::cout<<"exampleFunction called"<<std::endl;
//call the function on the passed object
(obj.*callable)(args...);
}
int main()
{
Actions action;
exampleFunction(action, &Actions::doSmthg); //calls doSmthg member function with 0 arguments
exampleFunction(action, &Actions::multipleArgs, 5,7);//calls multipleArgs member function with 2 int arguments
Entity e;
exampleFunction(e, &Entity::func,4.4); //calls func member function
}