课程: C++ Development: Advanced Concepts, Lambda Expressions, and Best Practices

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

What is move semantics?

What is move semantics?

- [Instructor] Move semantics represents an important and valuable addition to the C++ language. Move semantics was added to the language with the C++11 standard. To illustrate the need for move semantics, let's consider an example without move semantics. This is a function that takes an object of type T and returns an object of the same type. This function uses Call by Value, which means that when the function is called, an object is constructed for use by the function. This object has the scope of the function, so it's considered temporary. Because the function also returns by value, another new object is constructed for the return value. At this point, two new objects have been constructed, one of them is a temporary object that's only used for the duration of the function. When the new object is created for the return value, the copy constructor is called to copy the contents of the return object to the new object, b.…

内容