메서드 뒤 const

OpenJR·2024년 4월 3일
class Player
{
private:
  int num;
...
public:
  int get() contst {
      std::cout << num << std::endl;
  }
}

같이 메서드 뒤에 const가 붙는 메서드는 사실 인자로

int get(const Player* this)

처럼 자기 자신을 const 포인터로 받는 것과 동일하다.
그러므로 내부의 멤버변수나 메서드를 변경하는 것이 불가능한 것이다.

출처: Ch 01. 클래스 - 07. const

profile
Jacob

0개의 댓글