본문 바로가기

프로그래밍 언어/C++

pointer conversions에 대해

반응형

conversion의 설계 개념

C++의 conversion를 정의할 때, 직교하는 3 요소, value category, cv-qualification, data representation를 설계 개념으로 사용한다. conversion를 설계할 때, 요소 중 하나만을 변형하고, 다른 요소를 변형하지 않는다. 어떤 이유로, 예를 들어 하위 호환성을 위해, 설계 개념을 위반할 때는 관련된 특수 조항을 스펙 문서에 별도로 명시한다.

pointer conversions

data representation 요소를 변형하기 위해 설계한 conversion이다. data representation를 변경하기 때문에, conversion rank로 분류된다. 또한 일반적으로 value category이나 cv-qualification를 변경하지 않는다.

pointer conversionsprvalue category에서 prvalue category로 변환을 정의한다.

0 value를 갖는 integer literal type 또는 std::nullptr_t typeprvalue categorynull pointer constant라고 한다.

null pointer constant를 type Tpointer로 변경할 수 있다. conversion 결과는 T typenull pointer value를 갖고, T 타입의 다른 pointer value과 구별된다. 같은 type의 두 null pointer valuecompare equal하다. null pointer conversion에서 T typecv-qualified null pointer conversion로 변환은 pointer conversionqualification conversion를 적용한 변환이 아닌 단일 변환이다. 이와 같은 conversion를 null pointer conversion이라고 부른다.

integer literal typestd::nullptr_t typeprvalue category로 변경할 수 있다.

object type T에 대해, pointer to cv T type의 prvalue category를 pointer to cv void type의 prvalue category로 변경할 수 있다. 이 변환으로 pointer value 자체는 변경되지 않는다.

BDbase class이고, Dcomplete type인 경우에 대해, pointer to cv D type의 prvalue category에서 pointer to cv B type의 prvalue category로 변경할 수 있다. D를 통해 B를 접근할 수 없거나 base class가 애매하면, 컴파일 오류다. 변환 결과는 derived class objectbase class subobject에 대한 pointer다. null pointer value는 목적 타입의 null pointer value로 변경할 수 있다.

반응형