C++????些?锟�?const?梅??????
???????????? ???????[ 2014/5/5 11:25:07 ] ????????C++ const
???????const????
?????????????尾???const???????????????????????????????????????????????????????????
????1??const????
????2?????const????????
????3????const?????????
????4????????????const????
??????????????const??????尾危?????????const?????????????魏????澹�????????????????????????????????????????浠�???
1 int main(void)
2 {
3 int var = 42;
4 fun(var);
5 cout << var << endl; // print 42
6 return 0;
7 }
8 void fun( int i)
9 {
10 i = 10;
11 }
????????????????????????????????????写??????????????const?????????????蔚?????
????????????????????????????????????????尾????????蔚??????????????????谓??斜???????????????????????尾?????const????????????谩?
1 void fun( const int* p)
2 {
3 *p = 42; // error
4 int var = 10;
5 p = &var; // ??????p??????
6 }
7 void fun(const int& p)
8 {
9 p = 42; // error??p????????const?????????
10 }
?????械??????????????????????????const??????????????????????????????????????????*???????
1 class Rational{
2 // ....
3 };
4 const Rational operator* (const Rational& lhs?? const Rational& rhs);
5 Rational a?? b?? c;
6 a*b = c; // Error????????????const????
??????????????????????????????????const???????a*b=c?????????????????????????????????????????????违????????????????????????????????????????????????
??????

???路???
??????????????????
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