๋ฐ์ํ
[C++] keyword: const
[C++] keyword: const
2020.07.221. ์ค๋ช
const ํค์๋์ ํจ๊ป ์ ์ํ ๋ณ์์ ๊ฐ์ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค. ์ฆ, ์์ํ ๋์ด๋ฒ๋ฆฌ๋๋ฐ ํ๋ก๊ทธ๋๋ฐ ์ ๋ฐ๋๋ฉด ์ ๋ ๊ฐ์ด ์์ ๊ฒฝ์ฐ ์ ์ฉํ๋ค. ์ฝ๋๊ฐ ๊ธธ์ด์ง ์ค์๋ก ๋ณ์์ ๊ฐ์ด ๋ฐ๋์ด ์ง๋ ๊ฒ์ ๋ฐฉ์งํ ๊ฒฝ์ฐ ํ์ฉํ ์ ์๋ค. 2. ์์ 2.1) ์ผ๋ฐ์ ์ธ ๊ฒฝ์ฐ const int a = 1; a = 5; // error! ํ๋ฒ ์ค์ ๋ a๋ read-only memory์ ์ฌ๋ผ๊ฐ๊ฒ ๋๊ณ ๋ณ๊ฒฝํ ์ ์๊ฒ ๋๋ค. 2.1) ํจ์ ๋ด ์ธ์๊ฐ์์ ํ์ฉํ๋ ๊ฒฝ์ฐ class Child { public: int age; string name; string address; Child() = default; Child(int age, string name, string address) : age(age), name..