このケースに来たとき、コンパイルエラーを追跡していました:
struct Y
{
int&& y;
Y(int&& y)
: y(y)
{
}
};
struct ZZ {};
struct Z
{
ZZ&& z;
Z(ZZ&& z)
: z(z)
{
}
};
これらは両方とも次のように失敗します。
exec.cpp: In constructor ‘Y::Y(int&&)’:
exec.cpp:57:10: error: invalid initialization of reference of type ‘int&&’ from expression of type ‘int’
exec.cpp: In constructor ‘Z::Z(ZZ&&)’:
exec.cpp:67:10: error: invalid initialization of reference of type ‘ZZ&&’ from expression of type ‘ZZ’
しかし、その理由は正確にはわかりません。ここで何が問題なのですか?
-std=gnu++0x オプションで g++4.5.3 を使用していますが、-std=c++0x オプションでも発生します。