Cpp クラス const 新しいページはコチラ
提供: yonewiki
(→クラス const) |
(→クラス const) |
||
78行: | 78行: | ||
void CConst001::mfpub_Set_m_nValueConstPara(const int nPara1){ | void CConst001::mfpub_Set_m_nValueConstPara(const int nPara1){ | ||
− | //nPara1 = mpub_nValue; | + | //nPara1 = mpub_nValue;★1.const付きの引数は関数内で変更できない。 |
m_nValue = 1000; | m_nValue = 1000; | ||
printf("mfpub_Set_m_nValueConstPara\n", mpub_constnValue); | printf("mfpub_Set_m_nValueConstPara\n", mpub_constnValue); | ||
143行: | 143行: | ||
と、ここにきて、上記のような、どうでもいい説明を入れてみました。 | と、ここにきて、上記のような、どうでもいい説明を入れてみました。 | ||
+ | |||
+ | |||
+ | 4行目と12行目の関数では、メンバ関数の引数にconstがあるかないかの違いになっています。メンバ関数のプロトタイプ宣言(xxx.hファイルの方の記述)ではconstをつけてもつけなくても、効力はありません。 | ||
+ | |||
+ | '''void CConst001::mfpub_Set_m_nValue(int nPara1){''' | ||
+ | |||
+ | |||
+ | '''void CConst001::mfpub_Set_m_nValueConstPara(const int nPara1){''' | ||
+ | |||
+ | |||
+ | ★1.部分のようにnPara1という引数の中身を関数の中で書き換えて利用するようなことがconst付きの方では出来なくなっています。 |