Last active
January 18, 2016 10:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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