0
我写了结构MyParam
,以便它可以使用任意数量的参数进行实例化,在本例中为int
和bool
。出于封装原因,我希望MyParams
包含自己的promise
,以便它可以报告何时完成某件事情。但是当我将这个语句添加到结构中时,它失败了。尽管如此,作为一个全球性的公司,它运作良好下面是代码:当包含一个std :: promise作为成员时,为什么make_unique结构失败?
#include <tuple>
#include <memory>
#include <future>
//std::promise<bool> donePromise; // OK: if at global level, then make_unique error goes away
template< typename... ArgsT >
struct MyParams
{
MyParams(ArgsT... args) : rvalRefs { std::forward_as_tuple(args...) } {}
std::tuple<ArgsT...> rvalRefs;
std::promise<bool> donePromise; // causes make_unique to fail when donePromise is a member of MyParams
};
int main()
{
int num { 33 };
bool tf { false };
MyParams< int, bool > myParams(num, tf); // OK
auto myParamsUniquePtr = std::make_unique< MyParams< int, bool > >(myParams);
std::future<bool> doneFuture = myParams.donePromise.get_future(); // OK: when donePromise is a global
return 0;
}
error C2280: 'MyParams<int,bool>::MyParams(const MyParams<int,bool> &)': attempting to reference a deleted function
什么我与问候到promise
语句作为成员失踪?