I have a struct A
that I would like to use as a wrapper for various classes containing member functions with the same signature.
struct A
{
int i;
A()
: i(0)
{
}
int Do(std::function<int()> Function)
{
i = Function();
// Do stuff with i
return i;
}
};
An example would be:
class B : public A
{
public:
int Func0() { return 4; }
int Func1() { return 8; }
void Interface()
{
std::cout << Do(Func0) << std::endl;
std::cout << Do(Func1) << std::endl;
}
};
But this is clearly wrong, how can I achieve this without using the C-style approach? (int (*f)()
)