나는 다음과 같은 코드가 있습니다표준 : : 바인딩은 참조를 잃지
#include <stdio.h>
#include <functional>
template <typename T>
auto callback(T&& func) ->decltype(func())
{
return func();
}
double test(double& value)
{
value=value+1.0;
return value;
}
int main(void)
{
double t=1.0;
printf("%f\n",t);
test(t);
printf("%f\n",t);
callback(std::bind(test,t));
printf("%f\n",t);
}
을 그리고 그것은 callback
기능을 의미
1.000000
2.000000
2.000000
대신 t
의 사본을 가지고 출력 t
을 참조하십시오. 나는 std::bind
때문에 완벽하게 전달되어야하므로 무슨 일이 일어 났는지 궁금합니다.