fork(2) download
  1. /// illustrating http://stackoverflow.com/a/99622/2932052 (variation)
  2. /// under discussion in http://stackoverflow.com/q/30780171/2932052
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class A
  7. {
  8. int id;
  9. public:
  10. A(int i): id(i) {}
  11. int callFoo() { return foo(); }
  12. virtual int foo() = 0;
  13. };
  14.  
  15. class B: public A
  16. {
  17. public:
  18. B(): A(callFoo()) {}
  19. int foo() { return 3; }
  20. };
  21.  
  22. int main() {
  23. B b;
  24. cout << b.callFoo() << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
3