代码如下:
class A{
public:
A(int a){}
};
void fun1 (A & a )
{
return;
}
int fun2()
{
fun1(A(1));
return 0;
}
保存为test.cpp
在windows下编译会编译通过,在linux下不会编译通过
linux下会出现以下错误
$ g++ test.cpp
test.cpp: In function `int fun2()':
test.cpp:12: error: invalid initialization of non-const reference of type 'A&' from a temporary of type 'A'
test.cpp:7: error: in passing argument 1 of `void fun1(A&)'
说明不能从一个临时对象转换到一个非const的引用。
在windows下会出现一个警告。
m:/test.cpp(12) : warning C4239: 使用了非标准扩展 : “参数”: 从“A”转
换到“A &”
非常量引用只能绑定到左值
如果要统一到一致的情况,需要在windows编译时添加参数 -we4239,意思是将4239这个警告视为一个错误,强制开发人员修改代码。
openoffice代码在solenv/inc/wntmsci11.mk 194行添加CFLAGSWARNCXX += -we4239