c 臨時物件初始化指標和引用?

時間 2021-06-05 12:14:58

1樓:楚軒

1.因為你開啟了VS2013的非標準擴充套件.你把警告等級W4開了就知道了.這是微軟搞得

2.一樣是非標準擴充套件nonstandard extension used : class rvalue used as lvalue

2樓:邱昊宇

出現這種疑問時,可以嘗試換個編譯器……

比如 g++

main.cpp:5:11: error: '::main' must return 'int'

void mainmain.cpp: In function 'int main()':

main.cpp:7:

23: error: invalid initialization of non-const reference of type 'base&' from an rvalue of type 'base'

base& ref3 = basemain.cpp:8:22: error: taking address of temporary [-fpermissive]

base* p1 = &base

比如 clang++

main.cpp:5:1: error: 'main' must return 'int'

void main()

^~~~

intmain.cpp:7:

11: error: non-const lvalue reference to type 'base' cannot bind to a temporary of type 'base'

base& ref3 = basemain.cpp:8:

16: error: taking the address of a temporary object of type 'base' [-Waddress-of-temporary]

base* p1 = &base3 errors generated.

C 函式返回常引用給常引用初始化的問題,大家可不可以幫幫我?

黃亮anthony std string get std string t return t 就能滿足這裡的要求。謹慎所有返回引用函式 記憶體塊生命週期 不說人話 字串字面值隱式構造了string物件,get的引數引用了該string物件。但是該物件產生於get函式執行週期內,且由該週期內的棧持有,...

C 類本身的初始化和靜態欄位的初始化到底發生在什麼時候?

餘葉 其實就兩個構造器。乙個是靜態的,乙個是普通的。靜態構造器得需要你第一次訪問到該類的時候會被觸發。建立的時候,包括 static 成員變數的初始化和static構造器,其實 static 成員變數會整合進static構造器裡面的。而普通成員變數也會整合進普通構造器裡面的。 天煞 如 Sai說的,...

為什麼C語言指標初始化左邊是值,右邊是位址?

一直流浪 左邊是變數名,右邊必須賦值位址,c 5 int a c 相當於int a a c int 是資料型別,a是變數,一定要分開,先分清變數和資料型別你說的printf d a 其實是指標的乙個操作,取值操作,拿到指標a那片儲存空間的資料,即c的位址 追遠 J int a n 是 int a a...