当我遇到这种情况时,我正在追踪一个编译错误:
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’
但我不确定为什么。这里有什么问题?
我将 g++4.5.3 与 -std=gnu++0x 选项一起使用,但它也与 -std=c++0x 选项一起使用。