Page 99 - DCAP404 _Object Oriented Programming
P. 99
Object-oriented Programming Anil Sharma, Lovely Professional University
Notes Unit 5: Static Members
CONTENTS
Objectives
Introduction
5.1 Static Member
5.1.1 Static Member Functions
5.2 The Const Keyword
5.2.1 The Class Keyword
5.3 Static Objects
5.4 Friend Functions
5.4.1 Friend Function in Empty Classes
5.4.2 Friend Function in Nested Classes
5.4.3 Friend Function in Local Classes
5.5 Summary
5.6 Keywords
5.7 Review Questions
5.8 Further Readings
Objectives
After studying this unit, you will be able to:
Recognize the static members
Describe the const and class keyword
Explain the static objects
Discuss the friend function
Introduction
Static data members of a class in namespace scope have external linkage. Static data members
follow the usual class access rules, except that they can be initialized in file scope. Static data
members and their initializers can access other static private and protected members of their
class. The initializer for a static data member is in the scope of the class declaring the member.
A friend function is a function that is not a member of a class but has access to the class’s private
and protected members.
5.1 Static Member
Member data items of a class can be static. Static data members are data objects that are common
to all objects of a class. They exist only once in all objects of this class. The static members are
used when the information is to be shared. They can be public or private data. The main advantage
92 LOVELY PROFESSIONAL UNIVERSITY