vendredi 1 avril 2016

Assigning std::function

The following code compiles but yields undefined output in VC++ 2015 (release) and a runtime error with other compilers.

#include <functional>
#include <iostream>
int main()
{
    std::function<int(int)> f = [](int x) { return x; };
    std::function<const int&(const int& x)> g = f;
    std::cout << g( 42 ) << std::endl;
}

Why is the assignment g = f; allowed?

Aucun commentaire:

Enregistrer un commentaire