I am involved in exploring the power of C ++ 11, and as part of this, I plunge my head first into the world unique_ptrand shared_ptr.
When I started, I wrote code that I used unique_ptrexclusively, and therefore, when I was passing my variables around, I needed to do this with std::move(or so I understood).
After some effort, I realized what I really needed shared_ptrinstead of what I was doing. Quick search / replace later and my pointers were switched to general, but lazily I just left the calls move().
To my surprise, this compilation not only worked, but also worked great in my program, and I got every ounce of functionality that I expected ... especially, I was able to "move" shared_ptrfrom ObjectA to ObjectB, and both objects had access to it and could manipulate it. Fantastic.
This raised a question for me, though ... move()does the call actually do anything when I'm on shared_ptr? And if so, then what, and what are the consequences of this?
Code example
shared_ptr<Label> lblLevel(new Label());
levelTest = lblLevel;
this->guiView.AddSubview(move(lblLevel));
At this point, I can make important changes to levelTest, such as changing the text, and these changes are reflected on the screen.
, levelTest shared_ptr - , move() . . . MinGW Windows.