출처: MSDN
C++ Language ReferenceNote The examples in this section illustrate correct and incorrect usage when operators are not overloaded. By overloading operators, you can make an expression such as
C++ Language Reference
L-Values and R-Values
C++에서 표현은 l-value이나 r-value로 평가된다. L-value는 void 가 아닌 타입을 평가하하고, 변수를 나타내는 표현이다.
L-value는 할당 문장의 왼쪽에 나타난다(때문에 l-value의 "l"이다). 일반적으로 l-value인 변수는 const 키워드를 사용해 변경이 불가능하게 될 수 있다; 이것들은 할당연산자의 왼쪽에 있을 수 없다. 참조 타입들은 항상 l-value이다.
"r-value" 용어는 때때로 표현의 값을 설명하기 위하거나, l-value에서 그것을 분간하기 위해 사용된다.
모든 l-value은 r-value이지만, 모든 r-value가 l-value는 아니다.
Some examples of correct and incorrect usages are:
// lValues_rValues.cpp
// C2106 expectedint main(){
int i, j, *p;
i = 7; // Correct. A variable name, i, is an l-value.
7 = i; // C2106. A constant, 7, is an r-value.
j * 4 = 7; // C2106. The expression j * 4 yields an r-value.
*p = i; // Correct. A dereferenced pointer is an l-value.
const int ci = 7; // Declare a const variable.
ci = 9; // C2166 ci is a nonmodifiable l-value, so the
// assignment causes an error message to
// be generated.
((i < 3) ? i : j) = 7; // Correct. Conditional operator (? :)
// returns an l-value.}
j * 4
an l-value.
See Also
'망각 > Obj/C/++/#' 카테고리의 다른 글
포인터 변수에 const 사용 (0) | 2007.04.13 |
---|---|
L-Value and R-Value Expressions - MSDN (0) | 2006.05.26 |
VC++ 에서 콘솔창 띄우기 (0) | 2006.05.25 |
strncmp로 문자열 비교중 삽질 (0) | 2006.05.05 |