c++ - Noncopyable and move constructor -
i have made member of class non-copyable have given move constructor , assignment operator. yet dosn't play ball container vector.
class noncopyable { public: noncopyable(const noncopyable&) = delete; noncopyable& operator=(const noncopyable&) = delete; protected: noncopyable() { } ~noncopyable() _noexcept { } }; class member : noncopyable { public: member(int i) : mnum(i) { } ~member() { } member(member&& other) _noexcept : mnum(other.mnum) { } member& operator= (member&& other) _noexcept { std::swap(mnum, other.mnum); return *this; } private: int mnum; }; struct item { item(int i) : mmember(i) { } member mmember; }; int _tmain(int argc, _tchar* argv[]) { std::vector<item> vec; vec.emplace_back(1); return 0; }
the following compiler error:
error c2280: 'noncopyable::noncopyable(const noncopyable &)' : attempting reference deleted function see declaration of 'noncopyable::noncopyable' diagnostic occurred in compiler generated function 'member::member(const member &)'
why dosn't compiler recognize member
can moved? missing?
edit: visual studio 2013
edit2: add item
, compiles:
item(item&& other) _noexcept : mmember(std::move(other.mmember)) { }
am ok? it?
in vs2013 default , deleted functions , rvalue references partially implemented. upgrade vs2015 these feature according microsoft implemented (your example compiles fine). c++11/14/17 features in vs 2015 rc
Comments
Post a Comment