How does the following code work?

后端 未结 2 1374
逝去的感伤
逝去的感伤 2020-12-08 14:57
    #define TYPE_CHECK(T, S)                                     \\
    while (false) {                                              \\
      *(static_cast

        
2条回答
  •  抹茶落季
    2020-12-08 15:42

    Quite a fancy hack - the purpose of the macro seems to be to check if the type S is assignable to (i.e., is a subclass of) the type T. If it is not, the pointer cast from S* to T* will produce a compiler error. The while (false) prevents the code from actually having any other effect.

提交回复
热议问题