我有一个类,看起来像这样:
template<typename T> using VectorPtr=std::vector<std::unique_ptr<T>>; template<typename T> using VectorRawPtr=std::vector<T*>; class ItemsSet{ // <-- Compiler say this line contans an error 0_o ? public: ItemsSet(VectorPtr<Item>& items); ~ItemsSet() = default; VectorRawPtr<Item> GetItems(); VectorRawPtr<Item> GetSuitableItemsForPeriod(const IPeriod &period); double CalculateTotal(); private: VectorPtr<Item> _items; };
构造函数看起来像:
ItemsSet::ItemsSet(VectorPtr<Item> & items) { for(auto &itm: items){ _items.emplace_back(std::move(itm)); } }
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_construct.h: In instantiation of 'void std::_Construct(_T1*,_Args&& ...) [with _T1 = std::unique_ptr<Item,std::default_delete<Item> >; _Args = {const std::unique_ptr<Item,std::default_delete<Item> >&}]': /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_uninitialized.h:75:18: required from 'static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator,_InputIterator,_ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::unique_ptr<Item,std::default_delete<Item> >*,std::vector<std::unique_ptr<Item,std::default_delete<Item> >,std::allocator<std::unique_ptr<Item,std::default_delete<Item> > > > >; _ForwardIterator = std::unique_ptr<Item,std::default_delete<Item> >*; bool _TrivialValueTypes = false]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_uninitialized.h:126:15: required from '_ForwardIterator std::uninitialized_copy(_InputIterator,std::default_delete<Item> >*]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_uninitialized.h:281:37: required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator,_ForwardIterator,std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::unique_ptr<Item,std::default_delete<Item> >*; _Tp = std::unique_ptr<Item,std::default_delete<Item> >]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_vector.h:322:31: required from 'std::vector<_Tp,_Alloc>::vector(const std::vector<_Tp,_Alloc>&) [with _Tp = std::unique_ptr<Item,std::default_delete<Item> >; _Alloc = std::allocator<std::unique_ptr<Item,std::default_delete<Item> > >]' /cygdrive/d/code/itemSet.h:4:19: required from here /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_construct.h:75:7: error: use of deleted function 'std::unique_ptr<_Tp,_Dp>::unique_ptr(const std::unique_ptr<_Tp,_Dp>&) [with _Tp = Item; _Dp = std::default_delete<Item>]' { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }