const修饰符
?
一、 類的const對象
?
const 意謂著只讀 意謂著所標記的類成員變量不成出現(xiàn)在=號的左邊。
構造函數(shù)析構函數(shù)除外。
const Tdate d1(1988,8,18); //比如在存放出生日期的時候,我們不希望出生時間被修改,可以用const修飾
二、const成員函數(shù)?
?const放在函數(shù)尾部
?void fun(int a)const?
{ ?
? ? ? ? fun1() const;
};
注意:
?1.建議將所有不修改成員變量的函數(shù),用const修飾
?2. ?const A a;
? ? ?a.fun()//當a被const修飾,要想使用函數(shù)fun,函數(shù)fun必須也被const修飾,函數(shù)fun包含的fun1也應該被修飾
?
轉載于:https://blog.51cto.com/yhj51blog/1675523
總結
- 上一篇: [CareerCup] 1.6 Rota
- 下一篇: 贷前贷中贷后风险管理