본문 바로가기

C/C++

C++ Casting

C++ Casting


C++에서 타입 변환, 캐스팅, 형 변환 이라고 다양하게 불리는 녀석을 정리!




cpp_casting_dt.vsdx




귀찮다고 사용한 C style 캐스팅으로인해 생긴 버그 때문에 밤새가며 어셈블리 코드와 씨름하기 싫다면...

*IMPORTANT* C style의 캐스팅은 절대 사용하지 말것!!


  1. static_cast only succeeds if either the values are convertible or the pointers/references are compatible
  2. dynamic_cast only casts between proper class hierarchic.
  3. const_cast only works if source and target are cv-qualified versions of one another.
  4. reinterpret_cast states explicitly that you wish to examine an underlying binary representation. Most "reinterpret_cast" can be eliminated with proper design. In other words "reinterpret_cast" is needed means, most-likely something is wrong in the design.


'C/C++' 카테고리의 다른 글

errno 의미  (0) 2015.12.13
C에서 Try-Catch 사용하기  (0) 2015.12.13
개미수열  (0) 2015.03.04
C++11 Stringtokenizer  (0) 2015.01.26
C++11 강제  (0) 2015.01.26