October 2011
Beginner to intermediate
1200 pages
35h 33m
English
C++11 adds move semantics to the string class. As described in Chapter 18, this involves adding a move constructor, which uses an rvalue reference instead of an lvalue reference:
basic_string(basic_string&& str) noexcept;
This constructor is invoked when the actual argument is a temporary object:
string one("din"); // C-style string constructorstring two(one); // copy constructor – one is an lvaluestring three(one+two); // move constructor, sum is an rvalue
As discussed in Chapter 18, the intent is that string three takes ownership of the object constructed by operator+() rather than copying the object and then letting the original be destroyed.
The second rvalue constructor additionally ...
Read now
Unlock full access