これは、ScottMeyersによるC++11ノートサンプルのコードです。
int x;
auto&& a1 = x; // x is lvalue, so type of a1 is int&
auto&& a2 = std::move(x); // std::move(x) is rvalue, so type of a2 is int&&
理解に苦労していますauto&&
。
私はある程度の理解を持っています、それから私はそれがタイプを作るべきでauto
あると言うでしょうauto& a1 = x
a1
int&
引用されたコードから、これは間違っているようです。
私はこの小さなコードを書き、gccの下で実行しました。
#include <iostream>
using namespace std;
int main()
{
int x = 4;
auto& a1 = x; //line 8
cout << a1 << endl;
++a1;
cout << x;
return 0;
}
出力=4 (newline) 5
次に、8行目をとして変更auto&& a1 = x;
して実行しました。同じ出力。
私の質問:auto&
等しいauto&&
?
それらが異なる場合、何をしauto&&
ますか?