代碼如下:
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