C++: Can virtual inheritance be detected at compile time?

后端 未结 8 423
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 10:55

I would like to determine at compile time if a pointer to Derived can be cast from a pointer to Base without dynamic_cast<>. Is this possible using templates and metaprogramm

8条回答
  •  礼貌的吻别
    2021-02-02 11:41

    Once converted to the base pointer, you can only get a runtime error (dynamic_cast). You can define the methods using templated params and get a compile error by using template specializations.

提交回复
热议问题