简体   繁体   中英

C++ std move document error?

Here is the document I am referring to. Both form has r-value reference as input ( T&& t ).

But we can put l-value as parameter of move , in my below example, a is a l-value, which is identifiable and memory-addressable.

Any thought is document is wrong?

#include <iostream>

int main() {
    string a = "hello";
    string b(std::move(a));
    std::cout << "a is: " << a << endl;
    std::cout << "b is: " << b << endl;
}

output,

a is: 
b is: hello

T&& t is not r-value reference. It is the forward reference, previously known as universal reference, the special case when used with template or auto parameters. Read this good explanation here https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM