개발공부/C++
상수에 대한 참조자
dyson_ok
2019. 10. 10. 17:18
#include <iostream>
int main() {
int &ref = 4;
std::cout << ref << std::endl;
}
위와 같이 작성하면 에러가 난다. 상수값은 바꿀 수 있는 여지가 있기 때문이다.
const int &ref = 4;
상수참조자로 선언하면 리터럴도 참조할 수 있다.
int a = ref;
는 a = 4; 와 동일한 문장이다.