헤더파일에서 함수가 아래와같이 되어 있습니다. 함수 앞은 반환타입인걸 알겠는데, 함수 뒤에 const는 어떤역할을 하나요?
bool abc() const {return true;}
this 포인터가 const라는 뜻입니다
어떤 클래스의 instance가 const 로 선언되었을 때, 호출될 수 있는 멤버 함수라는 뜻입니다.
class Something { ... public: void set_value(int value) {...} int get_value() const {...} } ... const Something s; ... int value = s.get_value(); // OK s.set_value(10); // compile error
this 포인터가 const라는 뜻입니다
this 포인터가 const라는 뜻입니다
어떤 클래스의 instance가 const 로
어떤 클래스의 instance가 const 로 선언되었을 때, 호출될 수 있는 멤버 함수라는 뜻입니다.
class Something { ... public: void set_value(int value) {...} int get_value() const {...} } ... const Something s; ... int value = s.get_value(); // OK s.set_value(10); // compile error