fork(7) download
  1. /// illustrating http://stackoverflow.com/a/99622/2932052
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. A *pThis;
  8. public:
  9. A()
  10. : pThis(this)
  11. {
  12. }
  13.  
  14. void callFoo()
  15. {
  16. pThis->foo(); // call through the pThis ptr which was initialized in the constructor
  17. }
  18.  
  19. virtual void foo() = 0;
  20. };
  21.  
  22. class B : public A
  23. {
  24. public:
  25. virtual void foo()
  26. {
  27. }
  28. };
  29.  
  30. int main() {
  31. // your code goes here
  32. B b;
  33. b.callFoo();
  34. return 0;
  35. }
Success #stdin #stdout 0s 3136KB
stdin
Standard input is empty
stdout
Standard output is empty