주의 : 공부하면서 정리한 내용이므로 오류가 있을 수 있습니다.


실습 과제 2-4 :


과제 2-3 의 해답을, Boost 형식 특질 라이브러리를 사용하지 않고 작성하라. 그리고 두 해답들을 비교하라.




이건 RTTI 의 기능을 사용해 간단하게 구현할 수 있었다.




그러나 안타깝게도 참조 정보가 전부 날라가는 것을 알 수 있다. 왜 이 정보가 날라가는지 검색을 해 보니 다음과 같은 답변을 찾을 수 있었다.


이는 typeid 가 작동하도록 제안된 방식이다. 당신이 typeid 를 reference type 의 type-id 에 적용할 때, type_info object 가 referenced type 을 참조한다.

ISO/IEC 14882:2003, 5.2.8 / 4 [ expr.typeid ] :

When typeid is applied to a type-id, the result refers to a type_info object representing the type of the type-id. If the type of the type-id is a reference type, the result of the typeid expression refers to a type_info object representing the referenced type. If the type of the type-id is a class type or a reference to a class type, the class shall be completely-defined. Types shall not be defined in the type-id.

출처 : http://stackoverflow.com/questions/5151875/typeid-doesnt-return-correct-type


그리고 변수에 대한 const 도 날라갔다는 것을 알 수 있다. 왜 이 정보가 날라가는지 검색을 해 보니 다음과 같은 답변을 찾을 수 있었다.


그것들은 같은 type 이 아니지만, typeid 연산자는 const 와 volatile 을 벗겨 낸다.

From section 5.2.8 [ expr.typeid ]

The top-level cv-qualifiers of the glvalue expression or the type-id that is the operand of typeid are always ignored.

출처 : http://stackoverflow.com/questions/8888960/why-typeid-returns-that-int-and-const-int-are-same-types


+ Recent posts