맴버 변수

    함수의 괄호 뒤에 const를 넣는 이유에 대해서

    여기 저기 검색을 해보니 함수 괄호 뒤에 const를 넣는 의미는, 멤버 변수의 값을 변경하지 않는다. 라는 의미라고 하더라구요(그리고 함수 괄호 뒤에 const를 넣는 함수는 멤벼함수일때만 가능하다고 하네요.) 간단한 실험을 준비해봤습니다. 1. 아래의 코드는 잘 실행되는 코드입니다. #include #include using namespace std; class Tester { private: char m_data[24]; public: void setData(char *input) { strcpy(m_data, input); } const char* getData() const { return m_data; } }; int main() { Tester test; test.setData((char*)..