我已经为测量函数运行时间编写了类。它的工作正常。但是,当我开始在我的项目中使用它来测量类方法的速度时,它会因以下错误而中断:
错误:无效使用非静态成员函数
这是我的测量功能:
template<typename F, typename... Args>
decltype(auto) Time::timer(F function, Args&&... args){
auto start = std::chrono::steady_clock::now();
auto ret = function(std::forward<Args>(args)...);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
std::cout << "elapsed time: " << elapsed_seconds.count() << "s\n";
return ret;
}
我如何将类方法传递给我的函数,或者我如何编写测量类方法速度的函数?