c++ - Why does this snippet not work in VS 2013? -



c++ - Why does this snippet not work in VS 2013? -

is there wrong code?

#include <memory> class foo { }; class bar { std::unique_ptr<foo> foo_; }; int main() { bar bar; bar bar2 = std::move(bar); }

i'm getting error:

1>c:\users\szx\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\main.cpp(13): error c2280: 'std::unique_ptr<foo,std::default_delete<_ty>>::unique_ptr(const std::unique_ptr<_ty,std::default_delete<_ty>> &)' : attempting reference deleted function 1> 1> [ 1> _ty=foo 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(1486) : see declaration of 'std::unique_ptr<foo,std::default_delete<_ty>>::unique_ptr' 1> 1> [ 1> _ty=foo 1> ] 1> diagnostic occurred in compiler generated function 'bar::bar(const bar &)'

but gcc able compile without errors: http://ideone.com/cidcgi

your code valid. vs2013 rejects because compiler doesn't implement implicit generation of move constructor , move assignment operator. note you're not allowed explicitly default them. alternative implement move constructor.

class bar { std::unique_ptr<foo> foo_; public: bar(bar&& b) : foo_(std::move(b.foo_)) {} bar() = default; };

from msdn: support c++11 features (modern c++)

"rvalue references v3.0" adds new rules automatically generate move constructors , move assignment operators under conditions. however, not implemented in visual c++ in visual studio 2013, due time , resource constraints.

c++ c++11 unique-ptr

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -