fork download
  1. #include <iostream>
  2.  
  3. class Base
  4. {
  5. private:
  6. int foo;
  7. protected:
  8. Base(int _foo)
  9. {
  10. foo = _foo;
  11. }
  12. public:
  13. virtual void Foo()
  14. {
  15. std::cout << foo << std::endl;
  16. }
  17. };
  18.  
  19. class DerivedA : public Base
  20. {
  21. public:
  22. DerivedA() : Base(123)
  23. {
  24. }
  25. };
  26.  
  27. class DerivedB : public Base
  28. {
  29. private:
  30. static int before(int x)
  31. {
  32. std::cout << "before" << std::endl;
  33. return x * 2;
  34. }
  35. public:
  36. DerivedB() : Base(before(123))
  37. {
  38. std::cout << "after" << std::endl;
  39. }
  40. };
  41.  
  42. int main() {
  43. Base *a, *b;
  44. a = new DerivedA();
  45. b = new DerivedB();
  46. delete a;
  47. delete b;
  48. return 0;
  49. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
before
after