1
와 표준 : : 바인드를 사용 할 수 없습니다 :내가 사용하는 경우 표준 : 약속
int a = 3;
std::function<void()> task1 = std::bind([](int a){}, std::move(a));
괜찮아,하지만 난 std::promise<int>
와 int
를 교체하는 경우 :
std::promise<int> p;
std::function<void()> task2 = std::bind([](std::promise<int> p){}, std::move(p));
G는 ++에서 오류가 발생합니다 :
를error: conversion from ‘std::_Bind_helper<false, main()::__lambda7, std::promise<int> >::type {aka std::_Bind<main()::__lambda7(std::promise<int>)>}’ to non-scalar type ‘std::function<void()>’ requested
std::function<void()> task2 = std::bind([](std::promise<int> p){}, std::move(p));
왜? std::promise
매개 변수를 바인딩 할 때의 문제점은 무엇입니까?
당신 말이 맞습니다. 'std :: function'에는 복사 가능한 타입이 필요합니다. 대신'std :: shared_ptr'을 사용할 것입니다. 매우 감사합니다! –