fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct Abstract {
  5. virtual void pure() = 0;
  6. virtual void impure() { cout << " Abstract :: impure() " << endl; }
  7. Abstract() {
  8. impure();
  9. pure(); // warning. technically undefined
  10. }
  11. ~Abstract() {
  12. impure();
  13. pure(); // warning. technically undefined
  14. }
  15. };
  16. void Abstract :: pure() { cout << " Abstract :: pure()" << endl; }
  17. struct X : public Abstract {
  18. virtual void pure() { cout << " X :: pure() " << endl; }
  19. virtual void impure() { cout << " X :: impure() " << endl; }
  20. };
  21. int main() {
  22. X x;
  23. x.pure();
  24. x.impure();
  25. }
Success #stdin #stdout 0.01s 2728KB
stdin
Standard input is empty
stdout
 Abstract :: impure() 
 Abstract :: pure()
 X :: pure() 
 X :: impure() 
 Abstract :: impure() 
 Abstract :: pure()