fork download
  1. #include <iostream>
  2.  
  3. class A {
  4. public:
  5. A(bool call) __attribute__((optnone)) {
  6. std::cout << "A() is constructed (this = " << static_cast<void*>(this) << ")\n";
  7. weird();
  8. }
  9. ~A() {
  10. std::cout << "A() is destructed (this = " << static_cast<void*>(this) << ")\n";
  11. }
  12. void weird() {
  13. hello();
  14. }
  15. virtual void hello() = 0;
  16. };
  17.  
  18. void A::hello() {
  19. std::cout << "Hello from A! (this = " << static_cast<void*>(this) << ")\n";
  20. }
  21.  
  22. class B : public A {
  23. public:
  24. B(bool call ) : A(call) {
  25. std::cout << "B() is constructed (this = " << static_cast<void*>(this) << ")\n";
  26. hello();
  27. }
  28. ~B() {
  29. std::cout << "B() is destructed (this = " << static_cast<void*>(this) << ")\n";
  30. }
  31. virtual void hello();
  32. };
  33.  
  34. void B::hello() {
  35. std::cout << "Hello from B! (this = " << static_cast<void*>(this) << ")\n";
  36. }
  37.  
  38. int main() {
  39. //B not_call(false);
  40. B call(true);
  41. }
Runtime error #stdin #stdout #stderr 0s 15232KB
stdin
Standard input is empty
stdout
A() is constructed (this = 0x7ffec4f45d60)
stderr
pure virtual method called
terminate called without an active exception