Der folgende Code kompiliert, aber liefert undefinierte Ausgabe in VC++ 2015 (Release) und einen Laufzeitfehler mit other compilers.Zuweisen von std :: function <int(int)> zu std :: function <const int & (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;
}
Warum ist die Zuweisung g = f;
zulässig?
kompiliert und führt perfekt mit Apfel klingeln –
Sehr relevant/möglich dupe: http://stackoverflow.com/q/32871606/2069064 – Barry