fork download
  1. #include <iostream>
  2.  
  3. template <typename Derived>
  4. struct A
  5. {
  6. static void do_thing() { Derived::do_thing_impl(); }
  7. };
  8.  
  9. struct B : public A<B>
  10. {
  11. friend A<B>;
  12. protected:
  13. static void do_thing_impl() { std::cout << "B impl" << std::endl; }
  14. };
  15.  
  16. struct C : public A<C>
  17. {
  18. friend A<C>;
  19. protected:
  20. static void do_thing_impl() { std::cout << "C impl" << std::endl; }
  21. };
  22.  
  23. struct D : public A<D>
  24. {
  25. friend A<D>;
  26. };
  27.  
  28. int main()
  29. {
  30. A<B>::do_thing();
  31. A<C>::do_thing();
  32. A<D>::do_thing();
  33.  
  34. return (0);
  35. }
Compilation error #stdin compilation error #stdout 0s 3340KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘static void A<Derived>::do_thing() [with Derived = D]’:
prog.cpp:32:8:   required from here
prog.cpp:6:51: error: ‘do_thing_impl’ is not a member of ‘D’
   static void do_thing() { Derived::do_thing_impl(); }
                                                   ^
stdout
Standard output is empty