constの意味あるの…?
class Hoge
{
private:
// メンバ変数は数百あるが全てmutable
mutable int x;
public:
// メンバ関数全てconst指定
void move()const
{
x += 100;
}
void func()const
{
x = 100;
}
};
void MoveHoge( const Hoge& foo )
{
foo.move();
}
int main()
{
Hoge hoge;
MoveHoge( hoge );
return 0;
}
使い方ヒント: 「これは臭う」という行を見付けたら、各行の
をクリックしてマーキングしておきましょう(要Twitter OAuth認証)
const Hoge hoge; としても MoveHoge が使えるようにしたんですね。分かります。せっかくだから、operator= も constメンバ関数として定義しましょう。
コメント投稿には、twitter認証が必要です。
Twitter認証
mutableの使いどころが分からない、設計ミスでは?