Phần 1
Rvalue
An rvalue usually represents a temporary value.
100
x + 1
std::string("EURUSD")Phần 2
Rvalue Reference
An rvalue reference binds to an rvalue.
std::string&& ref = std::string("EURUSD");Phần 3
Function Parameter
void process(std::string&& value);This parameter accepts temporary std::string values.
process(std::string("EURUSD"));A named variable cannot be passed directly because it is an lvalue.
Phần 4
Named Rvalue References
A variable may have type T&&, but using its name produces an lvalue expression.
int&& ref = 100;100 is an rvalue, while ref is an lvalue expression.
Phần 5
Key Rules
Literals are usually rvalues.
Temporary objects are rvalues.
Arithmetic results are usually rvalues.
Named variables are lvalues.
T&&binds to rvalues whenTis a concrete, non-deduced type.
Mã mẫu hoàn chỉnh
cpp11/20_22_rvalue/main.cpp
#include <iostream>
#include <string>
void publish(std::string&& symbol)
{
std::cout << symbol << '\n';
}
int main()
{
publish("EURUSD");
publish(std::string("BTCUSD"));
}Tự kiểm tra · không chấm điểm
Bạn đã hiểu những điểm nào?
Bài này chưa có danh sách tự kiểm tra trong nguồn.