Poniższy kod kompiluje, ale daje niezdefiniowane wyjście w VC++ 2015 (wydanie) i błąd runtime z other compilers.Przypisywanie std :: function <int(int)> do std :: function <const int i (const int & x)>
#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;
}
Dlaczego dozwolone jest zadanie g = f;
?
kompiluje i wykonuje doskonale z Apple Clang –
Bardzo istotne/możliwe dupe: http://stackoverflow.com/q/32871606/2069064 – Barry