I have class CallProtector that is supposed to call method with variable number of arguments which suppose to protect call via mutex, but I can't figure out how could I pass object's method with their arguments. Here what I have so far:
class CallProtector
{
public:
template<typename F, typename ...Args>
void callProtectedMethod(F& lambda, Args... args)
{
std::lock_guard<std::mutex> guard(m_guard);
lambda(args);
}
private:
std::mutex m_guard;
};
I am trying to use it this way:
class Car
{
public:
void updateEngine(int engineModelType) {}
};
int main()
{
Car alfaRomeo;
CallProtector callProtector;
callProtector.callProtectedMethod(&Car::updateEngine, 10);
return 0;
}
But I have compilation error saying
no instance of function template "CallProtector::callProtectedMethod" matches the argument list
Appreciate any help, thanks in advance.