I would like to pass class member functions as a template parameter as shown in below example in main
function. Could you please help? It is working fine, if I pass normal functions as input parameters.
template <int n>
class meta
{
public:
template <typename F1, typename F2>
void operator()(F1& f1, F2& f2)
{
if (f2())
{
f1(n);
}
}
};
class temp
{
public:
void func1(int x)
{
cout << "inside func1" << endl;
}
bool func2()
{
cout << "inside func2" << endl;
return true;
}
};
int main()
{
temp t;
meta<10>()(t.func1, t.func2); //not working, func1 and func2 are class member functions
//meta<10>()(func1, func2); //working, if func1 and func2 are normal functions (not part of the class)
}