| | | | | |

Static Member Variables 1

  • Keyword static
    1. inherited from C, retains its C meaning
    2. also adds semantics in context of classes
  • Principle - static associates with the class itself instead of with specific objects of the class
  • class IntArray
    {
    public:
      IntArray  ( size_t sz = 10 , int ivalue = 0 );
      ...
    public:
      static unsigned int objectCount_; // the number of objects currently in existence
    
    private:
      size_t size_;
      int *  data_;
    } ;
    

| | Top of Page | 6. C++ Classes Part 2: Advanced Features - 17 of 22