본문 바로가기

Native/C++

mutable

[code]#include <turboc.h>

class position
{
private:
    int x, y;
    char ch;
    // mutable은 상수 멤버 함수나 객체의 상수성을 완전히 무시해
    // 버린다 변수는 본질적으로 값을 마음대로 바꿀 수 있지만
    // const 에 의해 값 변경이 금지 된다. mutable은 이런 const
    // 의 값 변경 금지 기능을 금지하여 값 변경을 다시 허용하자는
    // 복잡한 지정을 한다
    mutable char info[256];
    
public:
    position(int ax, int ay, char ach)
    {
        x = ax;
        y = ay;
        ch = ach;
    }
    void outPosition() const
    {
        gotoxy(x, y);
        putch(ch);
    }
    void moveTo(int ax, int ay)
    {
        x = ax;
        y = ay;
    }

    void makeInfo() const
    {
        sprintf(info, "x=%d, y=%d, ch=%c\n", x, y, ch);
    }

    void outInfo() const
    {
        puts(info);
    }
};

void main()
{
    const position here(11, 22, 'Z');
    here.makeInfo();
    here.outInfo();
}[/code]

'Native > C++' 카테고리의 다른 글

revolve  (0) 2013.10.02
dArray  (0) 2013.10.02
const member function  (0) 2013.10.02
const member  (0) 2013.10.02
static member  (0) 2013.10.02