4
想象我有一个类型:为什么在这种情况下std :: function不起作用?
struct my_type
{
double operator()(int a)
{
return 3.1415;
}
};
然后我想将它包装在std::function
。考虑两种不同的方法:
my_type m_t;
std::function<double(int)> f(std::move(m_t));
std::cout << f(4) << std::endl;
一切工作很好如我所料,PI的第一个数字被打印出来。然后第二个办法:
std::function<double(int)> ff(my_type());
std::cout << ff(4) << std::endl;
在我看来,这个代码是绝对一样的第一个。 rvalue
作为function
包装的参数传递。但问题是,第二个代码不能编译!我真的不知道为什么如此。