1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
#include <iostream>

class X {
   private:
      const char* name;
   public:
      X(const char* name) : name(name) {
	 std::cout << "X \"" << name << "\" constructed" << std::endl;
      }
      ~X() {
	 std::cout << "X \"" << name << "\" destructed" << std::endl;
      }
};

class Y {
   static X x; // static member, defined below
};

X Y::x = "static member of Y"; // definition of Y::x

X x = "global variable";

int main() {
   std::cout << "main starts" << std::endl;
   static X x = "static variable within main";
   std::cout << "main ends" << std::endl;
}