سؤال

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?

هل كانت مفيدة؟

المحلول

Use std::is_abstract.

#include <type_traits>

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

See it in action.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top