Я хочу сделать что-то вроде этого:
template <class T,class t_function = t::default_function>
class foo
{
public:
static void bar(T t)
{
t.t_function();
}
};
class example1
{
public:
void default_function()
{
std::cout<<"test"<<std::endl;
}
};
class example2
{
public:
void someotherfunction()
{
std::cout<<"test2"<<std::endl;
}
};
//how to use it
foo<example1>::bar(example1()); //should work, since example1 has the default function
foo<example2,example2::someotherfunction>::bar(example2()); //should work too
Словом: я бы хотел, чтобы пользователь этой функции мог предоставить альтернативный метод для выполнения вместо метода по умолчанию.
Можно ли добиться этого в C ++ и если да, то как?