When to use reinterpret_cast?

前端 未结 11 1211
我寻月下人不归
我寻月下人不归 2020-11-22 08:41

I am little confused with the applicability of reinterpret_cast vs static_cast. From what I have read the general rules are to use static cast when

11条回答
  •  醉话见心
    2020-11-22 09:17

    template 
    outType safe_cast(inType pointer)
    {
        void* temp = static_cast(pointer);
        return static_cast(temp);
    }
    

    I tried to conclude and wrote a simple safe cast using templates. Note that this solution doesn't guarantee to cast pointers on a functions.

提交回复
热议问题