fork download
  1.  
  2. template<typename T>
  3. class Base
  4. {
  5. template<typename U>
  6. friend void f(void *ptr) {
  7. static_cast<Base<U>*>(ptr)->run();
  8. }
  9. protected:
  10. virtual void run() = 0;
  11. };
  12.  
  13. class A : public Base<A>
  14. {
  15. protected:
  16. virtual void run() {}
  17. };
  18.  
  19. /*
  20. class B : public Base<B>
  21. {
  22.   protected:
  23.   virtual void run() {}
  24. };
  25. */
  26.  
  27. int main()
  28. {
  29. A a;
  30. f<A>(&a);
  31. }
Success #stdin #stdout 0.01s 2720KB
stdin
Standard input is empty
stdout

Standard output is empty