Page 89 - DCAP404 _Object Oriented Programming
P. 89

Object-oriented Programming




                    Notes          }
                                   You should get the following output from this program.
                                   The present value of count is 1
                                   The present value of count is 2
                                   The present value of count is 3

                                   The present value of count is 4
                                   The present value of count is 5





                                      Task  Analyze how the static data member should be created and initialized before the
                                     main function control block begins.

                                   4.5 Access Specifiers

                                   Members of  a class  can access  other members  (properties and methods) of  the same  class.
                                   Functions, operators and other classes (corresponding objects) outside the class description of a
                                   particular class can also access members of that class. An access specifier decides whether or not
                                   a function or operator or class, outside the class description can access the members it controls
                                   inside its class description. The members an access specifier controls are the members typed
                                   under it in the class description (until the next specifier).
                                   We will use functions and classes in the illustrations of accesses to class members. We will not
                                   use operators for the illustrations.
                                   We will be using the phrase, external function. This refers to a function or class method that is
                                   not a member of the class description in question. When we say an external function can access
                                   a class member, we mean the external function can use the name (identifier of property or name
                                   of method) of the member as its argument or as an identifier inside its definition.





                                     Notes  Note that there is no specific order required for member access, as shown in the
                                     preceding example. The allocation of storage for objects of class types is implementation
                                     dependent, but members are  guaranteed to be assigned successively higher  memory
                                     addresses between access specifiers.

                                   4.5.1 The Public Access Specifier

                                   With the public access specifier, an external function can access the public members of the class.
                                   The following code illustrates this (read the explanation below):

                                   #include  <iostream>
                                   using  namespace  std;
                                   class  Calculator
                                   {
                                        public:
                                           int num1;



          82                                LOVELY PROFESSIONAL UNIVERSITY
   84   85   86   87   88   89   90   91   92   93   94