fork download
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. protected:
  6. virtual void do_thing_impl() = 0;
  7. public:
  8. virtual ~A(){}
  9. static void do_thing(A * _ptr){ _ptr->do_thing_impl(); }
  10. };
  11.  
  12. class B : public A
  13. {
  14. protected:
  15. void do_thing_impl(){ std::cout << "B impl" << std::endl; }
  16. };
  17.  
  18. class C : public A
  19. {
  20. protected:
  21. void do_thing_impl(){ std::cout << "C impl" << std::endl; }
  22. };
  23.  
  24. int main()
  25. {
  26. B b_;
  27. C c_;
  28.  
  29. A::do_thing(&b_);
  30. A::do_thing(&c_);
  31.  
  32. return (0);
  33. }
  34.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
B impl
C impl