[Cpp 개념공부] **Meaning of position of const(**const위치에 따른 의미차이)


[Cpp 개념공부] **Meaning of position of const(**const위치에 따른 의미차이)

1. const 변수const int n = 0; int const n = 0; n = 2; // Compile Error위의 두 코드는 의미가 같다.2. const 멤버 변수클래스 내부에도 const키워드를 사용해서 초기화를 할 수 있는데 반드시 초기화 리스트를 사용해야만 한다.class Example { const int n; Example(void) : n(1) {}// const int num = 1; }; class ERROR { const int N; Bar(void) { N = 1; // Compile Error } };위 와 같이 클래스에서 멤버변수를 const로 만들고 초기화 하고 싶다면 반드시 생성자 초기화 리스트를 써야하고 아래 클래스를 돌려보면 컴파일 에러가 발생하는 것을 알 수가 ..


원문링크 : [Cpp 개념공부] **Meaning of position of const(**const위치에 따른 의미차이)