fork(5) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. class has_foo
  6. {
  7. typedef char yes;
  8. typedef long no;
  9.  
  10. template <typename U, U> class signature_check;
  11. template <typename C> static yes test(signature_check<void (C::*)(int), &C::foo>*);
  12. template <typename C> static no test(...);
  13.  
  14. public:
  15. static const bool value = (sizeof(test<T>(0)) == sizeof(yes));
  16. };
  17.  
  18. struct Base
  19. {
  20. void foo(int);
  21. };
  22.  
  23. struct Derived : public Base
  24. {
  25. };
  26.  
  27.  
  28. int main() {
  29. cout << "Base: " << has_foo<Base>::value << endl;
  30. cout << "Derived: " << has_foo<Derived>::value << endl;
  31. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Base: 1
Derived: 0