fork(1) download
  1. #include <iostream>
  2. #include <stdexcept>
  3.  
  4. struct A {
  5. A() { test(); }
  6. void test() { f(); }
  7. virtual void f() = 0;
  8. };
  9.  
  10. // void A::f() {
  11. // std::cout << "A::f()" << std::endl;
  12. //}
  13.  
  14. struct B : public A{
  15. virtual void f() {
  16. std::cout << "B::f()" << std::endl;
  17. }
  18. };
  19.  
  20. extern "C" void __cxa_pure_virtual() {
  21. throw std::runtime_error("Oh shit. I just called a pure virtual function ;(");
  22. }
  23.  
  24. int main() {
  25. try {
  26. A *a = new B();
  27. a->f();
  28. } catch (std::exception &e) {
  29. std::cout << "Exception caught: " << e.what() << std::endl;
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
Exception caught: Oh shit. I just called a pure virtual function ;(