为什么我在以下代码中出现错误?我该如何解决?
#include <functional>
#include <iostream>
int foo()
{
std::cout << "::foo() \n";
return 0;
}
void bar()
{
std::cout << "::bar() \n";
}
template <typename T>
T Hook(const std::function<T()>& action, T def = T())
{
try
{
return action();
}
catch (const std::exception& ex)
{
}
catch (...)
{
}
return def;
};
int main()
{
std::function<int()> foo_func(foo);
Hook(foo_func);
std::function<void()> bar_func(bar);
// Hook(bar_func); // Error
}