Imagine I have a type:
struct my_type
{
double operator()(int a)
{
return 3.1415;
}
};
Then I'd like to wrap it in std::function
. Consider two different approaches:
my_type m_t;
std::function<double(int)> f(std::move(m_t));
std::cout << f(4) << std::endl;
Everything works nice as I expected, first digits of PI are printed. Then the second approach:
std::function<double(int)> ff(my_type());
std::cout << ff(4) << std::endl;
It seems to me, that this code is absolutely the same as the first one. rvalue
is passed as an argument for function
wrapper. But the problem is, that the second code doesn't compile! I have really no idea why so.
Aucun commentaire:
Enregistrer un commentaire