fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. template <typename Derived>
  5. struct A
  6. {
  7. static void do_thing() { Derived::do_thing(); }
  8. };
  9.  
  10. struct B : public A<B>
  11. {
  12. friend A<B>;
  13. protected:
  14. static void do_thing() { std::cout << "B impl" << std::endl; }
  15. };
  16.  
  17. struct C : public A<C>
  18. {
  19. friend A<C>;
  20. protected:
  21. static void do_thing() { std::cout << "C impl" << std::endl; }
  22. };
  23.  
  24. int main()
  25. {
  26. A<B>::do_thing();
  27. A<C>::do_thing();
  28.  
  29. return (0);
  30. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
B impl
C impl