How to check, if the class is abstract, at compile time?

浪子不回头ぞ 提交于 2019-12-07 08:27:00

问题


By an abstract class I mean the class with at least one pure virtual method. I want the compilation to fail, if the check shows that the class is not abstract.

Is it even possible?


回答1:


Use std::is_abstract.

#include <type_traits>

static_assert(std::is_abstract<T>(), "T ought to be abstract.");

See it in action.



来源:https://stackoverflow.com/questions/21369036/how-to-check-if-the-class-is-abstract-at-compile-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!