參考https://en.cppreference.com/w...下面,這一行:xvaluea[n],thebuilt-insubscriptexpression,whereoneoperandisanarrayrvalue;那么什么是arrayrvalue呢?參考https://en.cppreference.com/w...下面說到對(duì)于expr1[expr2]Whenappliedtoanarray,thesubscriptexpressionisanlvalueifthearrayisanlvalue,andanxvalueifitisn't(sinceC++11).什么時(shí)候數(shù)組不是一個(gè)左值呢?參考下面代碼structS{intiarr[10];inti;std::stringsarr[10];std::strings;};Sget(){returnS{};}templatevoidfoo(T&&v){}intmain(){foo(get().iarr[0]);//int&foo(get().i);//int&&foo(get().sarr[0]);//std::string&foo(get().s);//std::string&&return0;}根據(jù)cppreference的說法:get()返回的是prvalueget().m應(yīng)該是xvalueget().m[n]是xvalue嗎?
c++ 在什么情況下 a[n] 是一個(gè)右值?
慕虎7371278
2019-05-09 22:03:37