c++ - Class template where variable class derives from certain abstract class -
i want ensure in definition of following templated class b, class derives abstract class c. can this?
template <class a> class b { // must derive c ... };
i using c++11.
use std::is_base_of
:
template <class a> class b { static_assert(std::is_base_of<c, a>::value , "a must derive c"); //... };
note is_base_of<c, c>::value
true, may want use std::is_same
ensure a
not c
itself:
static_assert(std::is_base_of<c, a>::value && !std::is_same<c, a>::value , "a must derive c");
Comments
Post a Comment