c++ - When is a variable that is "replaced" no longer addressable -


If I specify a new variable to a variable, then the old variable is no longer addressed, though I'm not sure It goes out of the scope:

For example:

  std :: vector & lt; Int & gt; Foo () {return std :: vector & lt; Int & gt; {3,4,5}; } Int main () {std :: vector & lt; Int & gt; V {1,2,3}; V = foo (); // When is the first Vector District called? // "foo ()" has been said before or after? // Is it called? }  

And, if it is not called until Fu is called, before I call Fu ()?

  V = foo ();  

The above statement is a move assignment (assign a copy to the pre-C +11 compiler). In any case, the result of the call for foo () is required because it has input arguments in the respective assignment operator, so after v < / Em> to call foo () , and the memory management is done in the copy / move operation operator.

Not to mention any call for the destructor of v because at that point the district designer will not be able to call the memory Managed by v , will be removed with the destructors for different elements. vector & lt; Int & gt; In the case of , the Destructor of each int is NOP, so they only apply conceptually. vector will then assign enough memory (copy) assignment to be able to keep the content of vector returned by foo , or Take control of the memory being played back by foo (move the assignment)> vector . Certainly, the vector is free to leave the allocation after the implementation fund if it is sufficient to keep new material in the existing material.

v will run when v will be out of range, in the example given to you, this main () .

happens at the end

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -