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. hello();
  8. }
  9. ~A() {
  10. std::cout << "A() is destructed (this = " << static_cast<void*>(this) << ")\n";
  11. }
  12. virtual void hello() = 0;
  13. };
  14.  
  15. void A::hello() {
  16. std::cout << "Hello from A! (this = " << static_cast<void*>(this) << ")\n";
  17. }
  18.  
  19. class B : public A {
  20. public:
  21. B(bool call ) : A(call) {
  22. std::cout << "B() is constructed (this = " << static_cast<void*>(this) << ")\n";
  23. hello();
  24. }
  25. ~B() {
  26. std::cout << "B() is destructed (this = " << static_cast<void*>(this) << ")\n";
  27. }
  28. virtual void hello();
  29. };
  30.  
  31. void B::hello() {
  32. std::cout << "Hello from B! (this = " << static_cast<void*>(this) << ")\n";
  33. }
  34.  
  35. int main() {
  36. //B not_call(false);
  37. B call(true);
  38. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
A() is constructed (this = 0x7ffdc6730310)
Hello from A! (this = 0x7ffdc6730310)
B() is constructed (this = 0x7ffdc6730310)
Hello from B! (this = 0x7ffdc6730310)
B() is destructed (this = 0x7ffdc6730310)
A() is destructed (this = 0x7ffdc6730310)