参考https://en.cppreference.com/w...下面,这一行:xvaluea[n],thebuilt-insubscriptexpression,whereoneoperandisanarrayrvalue;那么什么是arrayrvalue呢?参考https://en.cppreference.com/w...下面说到对于expr1[expr2]Whenappliedtoanarray,thesubscriptexpressionisanlvalueifthearrayisanlvalue,andanxvalueifitisn't(sinceC++11).什么时候数组不是一个左值呢?参考下面代码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;}根据cppreference的说法:get()返回的是prvalueget().m应该是xvalueget().m[n]是xvalue吗?
2 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
简单的,(int[3]){1,2,3}此时这个就是一个右值数组,下标访问返回的为右值(xvalue),但通过偏移间接寻址后得到的恒为左值(以上写法在gcc和clang下正确),还有种写法为usingarryTY=int[3];arryTY{1,2,3}
添加回答
举报
0/150
提交
取消
