c++ - Who is responsible for deletion of heap allocated object when moving it? -


What happens when the class is created with new ones, and then the class constructor is executed? The original manufacturer is still responsible for the removal? The examples given below run fine (), but should they not crash in another area, because the vector emits the vector before the vector and hence removes the object?

I have clearly misunderstood here, then what is the ownership of Std :: move?

  #include & lt; Iostream & gt; # Include & lt; Memory & gt; #include & lt; Vector & gt; #include & lt; Utility & gt; Classroom owner {public: owner (): data_ (new int (1)) {} int & amp; Receive () {return * data_;} private: std :: unique_ptr & lt; Int & gt; Information_; Owner (Constant & amp;) = Deletion; Zero operator = (console owner & amp;) = delete; }; Int main () {{Master Owner; Std :: vector & lt; Integer & gt; testing; Test.emplace_back (std :: move (owner.get ())); Std :: cout & lt; & Lt; Test [0] & lt; & Lt; Std :: endl; } {std :: vector & lt; Int & gt; testing; {Owner's owner; Test.emplace_back (std :: move (owner.get ())); } Std :: cout & lt; & Lt; Test [0] & lt; & Lt; Std :: endl; } {Owner's owner; {std :: vector & lt; Int & gt; testing; Test.emplace_back (std :: move (owner.get ())); Std :: cout & lt; & Lt; Test [0] & lt; & Lt; Std :: endl; }}}}    

You are not taking any data here. When you call :: find () , then you are highlighting the context of int , and when you call std :: move () In that context, you are making a trivial artist to "steal" from std :: vector :: emplace_back () to owner There is nothing, because int does not have any driver.

I think that you think that std :: unique_ptr inside owner plays in these tasks, but it is not; You are removing that pointer, but never try to move its contents. To do this, you need to invite the driver or operator of the assignment operator of std :: unique_ptr .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -