????C++??????Щ????
???????????? ???????[ 2015/5/19 14:35:48 ] ????????????????
????C++??????????????????????????ò????????????????????????????????????????????????????????á?
????int val = 42;
????int &rval = val;
???????rval????val???????rval??val?????????????????????????е???????????????
???????????????????????????????????????????????????????У???????????????????е???????????????????????????????????????
????int &rval = 10; //error: initializer must be an object
????double dval = 3.14;
????int &rdval = dval; //error: initializer must be an int object
????References to const????????????
???????????????????????????????????????????
????const int ci = 1024;
????const int &r1 = ci;
????r1 = 42; //error: r1 is a reference to const
????int &r2 = ci; //error: nonconst reference to a const object
???????ci????????????????????????????????????????ci???????????????ci??
?????????????????????????????????????????????????????????const?????????????????????
????int i = 42;
????const int &r1 = i; ???? //ok
????const int &r2 = 42;????????//ok
????const int &r3 = r1 * 2;?? //ok
????int &r4 = r * 2; //error: ????????ò??????????????
???????????????????????
????double dval = 3014;
????const int &ri = dval; //ok
???????????????????????????
????double dval = 3014;
????const int temp = dval; //????????????????????????dval
????const int &ri = temp; //??????????????????
???????????????????????????????????????ò?????????????????????в??????????
?????????????????ò??????????
?????????????????????????ū???????????????????????????????????????????? ???????????????????????????????????????????????????????dval?????????????У???
?????????????г??????ò??????????????????????????????????????????????????????????????????????????????ó??????ó????????????????????????????б????????????????????????????????????????????л@Kvtis???????
?????????????
????int i = 42;
????int &r1 = i;
????const int &r2 = i;
????r1 = 0; //ok
????r2 = 0; //error
????????????????ú????????????????????????????????ò??????????????????????????????????????????????????????????????????????????????????????????????????????????????????棬??????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11