fork download
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. class CMother
  6. {
  7. private:
  8. void _CommonStuff()
  9. {
  10. cout << "work common to children" << endl;
  11. }
  12.  
  13. virtual bool _Compute() = 0;
  14. public:
  15. bool Compute()
  16. {
  17. _CommonStuff();
  18. _Compute();
  19. }
  20. };
  21.  
  22. class C1 : public CMother
  23. {
  24. private:
  25. virtual bool _Compute() override
  26. {
  27. cout << "work specific to C1" << endl;
  28.  
  29. return true;
  30. }
  31. };
  32.  
  33. class C2 : public CMother
  34. {
  35. private:
  36. virtual bool _Compute() override
  37. {
  38. cout << "work specific to C2" << endl;
  39.  
  40. return true;
  41. }
  42. };
  43.  
  44. int main() {
  45.  
  46. unique_ptr<CMother> c1(new C1);
  47. unique_ptr<CMother> c2(new C2);
  48.  
  49. c1->Compute();
  50. c2->Compute();
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
work common to children
work specific to C1
work common to children
work specific to C2