fork(28) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct base {
  5. static void talk() { cout << "hello" << endl; }
  6. static void shout() { cout << "HELLO!!" << endl; }
  7. };
  8.  
  9. struct derived : public base {
  10. static void talk() { cout << "goodbye" << endl; }
  11. };
  12.  
  13. template < class T >
  14. struct traits {
  15. static void talk() { T::talk(); }
  16. static void shout() { T::shout(); }
  17. };
  18.  
  19. int main() {
  20. traits<base>::talk();
  21. traits<base>::shout();
  22. traits<derived>::talk();
  23. traits<derived>::shout();
  24. return 0;
  25. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
hello
HELLO!!
goodbye
HELLO!!