Created
December 20, 2015 00:01
-
-
Save JossWhittle/a2e03a28292a2233dc4f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <type_traits> | |
| class A {}; | |
| class B {}; | |
| class C : public A {}; | |
| class D : public B {}; | |
| template<typename T> | |
| inline typename std::enable_if<std::is_base_of<A, T>::value>::type some_func(T obj) { | |
| printf("Derived call...\n"); | |
| }; | |
| template<typename T> | |
| inline typename std::enable_if<!std::is_base_of<A, T>::value>::type some_func(T obj) { | |
| printf("Normal call...\n"); | |
| }; | |
| int main(int argc, char *argv[]) { | |
| some_func(1); // Normal Call | |
| A a; some_func(a); // Derived Call | |
| B b; some_func(b); // Normal Call | |
| C c; some_func(c); // Derived Call | |
| D d; some_func(d); // Normal Call | |
| system("PAUSE"); | |
| return 0; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment