Skip to content

Instantly share code, notes, and snippets.

@xunkai55
Last active January 18, 2016 10:10
Show Gist options
  • Save xunkai55/3bea83c38f4f1a52f71f to your computer and use it in GitHub Desktop.
Save xunkai55/3bea83c38f4f1a52f71f to your computer and use it in GitHub Desktop.
use static assert to check if the template parameter is a class derived of another one.
#include <iostream>
struct A {} ;
struct B: public A {};
template<class T>
struct C {
static_assert(std::is_base_of<A, T>::value, "Wrong class parameter");
};
int main() {
// your code goes here
C<B> b;
C<A> a;
C<int> c;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment