C++Reference ?????λ??塱???
???????????? ???????[ 2014/9/1 16:47:05 ] ??????????????? ????? ???
????C++ ??????????????????????????“???”????????????????????κλ???VMA????-??????????????????????????????????????????????????C??????????????
????????????????????C++??????C++?????????????????????????????????е?????????????C++?????????????????????????????????????????????????Haskell??????????????? ??????????????????????????????????????????
??????????????????????????????????C++?????????????????????????????“reference"??????????????????????????
??????????????????“ http://blog.csdn.net/ly8838/article/details/38638491”????????reference????????????????????????????????reference???Щ????
???????????reference????????ò????????????? - ??????direct object?????.
????C++?У?????????“???????”??normal variable???? ????“?????”??value semantics??????rvalue ???? ?????????reference??????????????“???????”??????????????????о?????
????long x;
????MyClass m; // MyClass is a user defined class
????????x??m????“??????”????????????е??????????????????????????????????????????????????????????????????????????????????????object?У????????????????????Щ????????????????????????????????????????????????????????????“???????????primitive type variable??”???????÷?????????????C++??λ??????????????
??????????????C#??JavaScript?? ???????????????????????“??????”??????ж?????????????????????????“??????heap??”?У??????????“???”???????????“??????”???????"????????“???”??“reference”. ??????????????????????????????????????“???”??“reference”??
???????reference??????????????????????????http://en.wikipedia.org/wiki/Reference_(C%2B%2B)???????????????????????????“????”?????????????????“???”??“?????”?????????????
??????????????????“reference ???????alias (?????????)”??????????
????????????????????????alias??ν???“????”??????
????int x = int(10); // line1
????int & r = x; // line2: r is an alias of x
????r++; // line3: x is now 11
????r = 3; // line4: x is now 3
????assert (&r == &x); // line5: r points to x
??????????????????????????r ?? x ??????κ?????????????????棬?????????????C++?????????reference?????????????????“???”???????÷???
??????????????????????????????÷???????????“????????Σ???”????????????x ?? r ?????????????????
?????????x ??“??????”????r???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????object reference ?? direct object ????????????????д??????????????
???????????????line2 ???????? r = &x (?x???????????????????? reference ???????? ????line5???????????????“??????”?????????????????д?????????
????class X {…}
????void myXFunction(X x) {…}
????void myXFunction2(const X & x) {…}
??????????X& ?? X ??“alias”???????÷?????? ????????????myXFunction2??????????????X&???????X * ??????????????myXFunction2???????????myXFunction?????????X???????????“???”???myXFunction2????copy ????????copy??? ????????????????- shallow copy???? ??myXFunction???????????copy ??argument?????У??????????????- deep copy????
???????????????????????const X &x ???÷???????????????????????????ù????
??????
???·???
??????????????????
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