????(2)const ???κ????????
????const???κ??????????????????????????????const?????????????????????????????
????a.const int fun1() //?????????????壬????????????????????
????b. const int * fun2() //????? const int *pValue = fun2();
????//?????????fun2()????????????????????????????
????c.int* const fun3()   //????? int * const pValue = fun2();
????//?????????fun2()??????????????????????????
???????????£?????????????????????????軔???????const??????????????????????????????????const???κ??????????????????????????????????????????????????£????踐????????????const??const A test = A ????????????????????const??const A& test = A????? ???????????const???????????????????????A?е???У???????????????const??????????????????????и???????????????????·?????????
????4???????CONST
????(1)const???γ??????
????const?????????????????????????????????????????????????????????б??и????
????class A
????{
????…
????const int nValue;         //???????????????
????…
????A(int x): nValue(x) { } ; //?????????????б??и??
????}
????(2)const???γ??????
????const?????????????????ó???????????????в???????const????????????д?????????????Ρ?
????class A
????{
????…
????void function()const; //??????????? ?????????????????.
????//???????????в???????const?????????
????}
????????const?????/???/?????????????????const?????????????const???γ????????????????????????const???????á?
????a. const??????????????????????????????????????????
????b. const??????????????????const?????????????????????????
????(3)const?????????/???????/????????
????·  const????????????????????????????е???????????????????????????????????????????????
????·  const???ε?????????????????const??????????????????????????????const??????????и????????????????
???????磺
????class AAA
????{
????void func1();
????void func2() const;
????}
????const AAA aObj;
????aObj.func1(); ×
????aObj.func2(); ???
????const AAA* aObj = new AAA();
????aObj-> func1(); ×
????aObj-> func2(); ???
??????????Const??????????Const????????
???????const_cast ?????????
??????÷?????const_cast <type_id>  (expression)
???????????????????????const??volatile?????????const ??volatile??????? type_id??expression??????????????
????·  ????????????????????????????????????
????·  ????????????????????????????????????????
????·  ????????????????????
??????????const???Щ????
????·  ????????const?????????????????洦??????????????????????
????·  ????????????????????罫const????????????????????
????·  ??????????const???????????????????????????????????????
????·  const?????????е???????÷??????????????????????????????????
????·  ?????????????????????????const;
????·   ??????????????????????????????????????????const????;
????·  ?????????????????????????????????const ?????
?????塢??????????
????·  ????????????????????????????????????????????????????????????????
?????????????????????????????????static??const?????
????·  ?????????????????????????????static ?? const ???????????????????磺
????class A { public: A() {} private: static const int i; file://????????????? }??
????const int A::i=3;??????????????????????????б?? class A { public: A(int
????i=0):test(i) {} private: const int i; }?? ????????????????????
????·  ???????const????????У?this?????????????????????????const????????У?
????this????????const??????????????volatile????????У?this????????
????volatile????????
????·  new?????????????const??????