Page 102 - DCAP404 _Object Oriented Programming
P. 102

Unit 5: Static Members




                 {                                                                              Notes
                         cout  <<  count  <<  “\n”;
                 }
                 main()
                 {
                 cout  <<  “  Number  of  objects  created  before=”;
                 counter::disp();  //Calling  function  disp()  belonging  to  class  counter

                 counter  cntl,  cnt2,  cnt3,  cnt4,  cnt5;
                 cout  <<  “  Number  of  objects  created  recently=”;
                 counter::disp();
                 getche();
                 }
          You should get the following output on running the program.
                 Number of objects created before=0

                 Number of objects created recently=5
          In defining static functions you should take some precautions. A static member functions cannot
          be a virtual function.


               !
             Caution  A  static or non-static member function cannot have the same name and same
             arguments type.

          Self Assessment


          Fill in the blanks:
          1.   The …………………………….. should be created and initialized before the main function
               control block begins.

          2.   Class members can be declared using the ……………………. specifier static in the class
               member list.
          3.   Only one copy of the static member is shared by  all …………………….. of a class in a
               program.
          4.   When you declare an object of a class having a static member, the static member is not part
               of the……………………... .
          5.   A static member function does not have a ……………………. pointer.

          5.2  The Const Keyword

          The keyword, const (for constant), precedes the data type of a variable.
          Syntax

          const  <data  type>  <name  of  variable>  =  <value>;





                                           LOVELY PROFESSIONAL UNIVERSITY                                   95
   97   98   99   100   101   102   103   104   105   106   107