나는 reference_wrapper를 사용하여 reference_wrapper ctor로 전달 된 객체를 반환하는 functor를 생성 할 수 있다고 생각했습니다. 그러나 이것은 효과가 없습니다. 내가 잘못하고 있니? 그렇다면 더 좋은 방법이 있습니까? 나는 람다 (lambda)를 쓸 수 있는데, 그렇게해서는 안되는 것처럼 보입니다.reference_wrapper 원문 참조
#include <iostream>
#include <functional>
using namespace std;
void funPtrPrinter(function< int(void) > output)
{
cout << output() << endl;
}
int main(void)
{
int thirteen = 13;
auto refWrap = ref(thirteen);
funPtrPrinter(refWrap);
}
왜 'bind'? 람다 표현식은 이미 호출 가능합니다. – Oktalist
@Oktalist 아직도 편집 :) OP는 그가 람다 (그러나 왜)를 사용하고 싶지 않았다고 언급 했으므로 대안을 시연했습니다. – Praetorian
이것은 실제로 bind 내에서 람다를 사용합니다. –