使用std :: reference_wrapper作为成员的默认构造函数?

时间:2017-05-25 14:09:09

标签: c++ c++11 constructor reference-wrapper

我有这个结构:

struct MyStruct
{
    MyStruct(const Wrapper &wrapper, /*...*/) :
        wrapper(std::cref(wrapper)), /*...*/ {}

    std::reference_wrapper<Wrapper const> wrapper;
    /*...*/
};

但是,现在我想使用tbb::concurrent_bounded_queue<MyStruct>,这是不可能的,因为MyStruct没有默认构造函数。但我不知道如何定义它,因为必须以某种方式初始化wrapper。有没有解决方案(除了使用原始指针)?

tbb错误(此处FindAffineShapeArgsMyStruct):

/usr/include/tbb/concurrent_queue.h(453): error: no default constructor exists for class "FindAffineShapeArgs"
          T value;
            ^
          detected during:
            instantiation of "void tbb::concurrent_bounded_queue<T, A>::clear() [with T=FindAffineShapeArgs, A=tbb::cache_aligned_allocator<FindAffineShapeArgs>]" at line 446
            instantiation of "tbb::concurrent_bounded_queue<T, A>::~concurrent_bounded_queue() [with T=FindAffineShapeArgs, A=tbb::cache_aligned_allocator<FindAffineShapeArgs>]" at line 272 of "/home/luca/Dropbox/HKUST/CloudCache/cloudcache/CloudCache/Descriptors/hesaff/pyramid.cpp"

0 个答案:

没有答案