fork(1) download
  1. #include <iostream>
  2.  
  3. class A {
  4. public:
  5. A();
  6. ~A();
  7. void hello(const char* message);
  8. static A a;
  9. };
  10.  
  11. class B {
  12. public:
  13. B();
  14. ~B();
  15. void hello(const char* message);
  16. static B b;
  17. };
  18.  
  19. A::A() {
  20. std::cout << "A() is constructed\n";
  21. B::b.hello("constructur A()");
  22. }
  23.  
  24. A::~A() {
  25. std::cout << "A() is destructed\n";
  26. B::b.hello("destructor A()");
  27. }
  28.  
  29. void A::hello(const char* message) {
  30. std::cout << "Hello from A! (" << message << ")\n";
  31. };
  32.  
  33. A A::a;
  34.  
  35. B::B() {
  36. std::cout << "B() is constructed\n";
  37. A::a.hello("constructor B()");
  38. }
  39.  
  40. B::~B() {
  41. std::cout << "B() is destructed\n";
  42. A::a.hello("destructor B()");
  43. }
  44.  
  45. void B::hello(const char* message) {
  46. std::cout << "Hello from B! (" << message << ")\n";
  47. };
  48.  
  49. B B::b;
  50.  
  51. int main() {
  52. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
A() is constructed
Hello from B! (constructur A())
B() is constructed
Hello from A! (constructor B())
B() is destructed
Hello from A! (destructor B())
A() is destructed
Hello from B! (destructor A())