home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9203 / borhot / static.cpp < prev    next >
C/C++ Source or Header  |  1992-03-24  |  1KB  |  38 lines

  1. /* ------------------------------------------------------ */
  2. /*                      STATIC.CPP                        */
  3. /*      Initializing Static Class Members of Type Class   */
  4. /*              (c) 1991 Borland International            */
  5. /*                   All rights reserved.                 */
  6. /* ------------------------------------------------------ */
  7. /*            veröffentlicht in DOS toolbox 3'92          */
  8. /* ------------------------------------------------------ */
  9.  
  10. // declare a class
  11. class First {
  12.   public:
  13.     int count;
  14.     First() {}      // must have callable constructor
  15. };
  16.  
  17.   // declare class containing static member of class First
  18.  
  19. class Second {
  20.   public:
  21.     static First fVar;
  22. };
  23.  
  24.   // initialize static member of class Second
  25. First Second::fVar = First();
  26.   // initialize with explicit call to ctor
  27.  
  28. /* ------------------------------------------------------ */
  29.  
  30. int main(void)
  31. {
  32.   Second *sVarA = new Second;
  33.   delete sVarA;
  34.   return 0;
  35. }
  36. /* ------------------------------------------------------ */
  37. /*                      STATIC.CPP                        */
  38.