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