Skip to content

Instantly share code, notes, and snippets.

@JossWhittle
Created December 20, 2015 00:01
Show Gist options
  • Select an option

  • Save JossWhittle/a2e03a28292a2233dc4f to your computer and use it in GitHub Desktop.

Select an option

Save JossWhittle/a2e03a28292a2233dc4f to your computer and use it in GitHub Desktop.
#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