fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. using namespace std;
  4.  
  5. struct A{};
  6. struct B : public A{};
  7. struct Bb : B{};
  8. struct X {};
  9.  
  10. template<typename T>
  11. class D {
  12. static_assert(std::is_base_of<A,T>::value, "not derived from A");
  13. };
  14.  
  15. int main() {
  16. D<B>();
  17. D<Bb>();
  18. D<X>();
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 3408KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'class D<X>':
prog.cpp:18:7:   required from here
prog.cpp:12:2: error: static assertion failed: not derived from A
  static_assert(std::is_base_of<A,T>::value, "not derived from A");
  ^
stdout
Standard output is empty