Classes and Objects with Constructors/Destructors: Accessing Class Member, Member Function Definition and Nesting of Member Functions

Get unlimited access to the best preparation resource for IAS : Get complete video lectures from top expert with unlimited validity: cover entire syllabus, expected topics, in full detail- anytime and anywhere & ask your doubts to top experts.

Download PDF of This Page (Size: 144K)

Image of Defining member function

Image of Defining Member Function

Image of Defining member function

Accessing Class Member

Through object, data member and member function present in public can be accessed. The general format is:

Object name. data member.

Object name. member function.

The dot operator is called the class member access operator.

Member Function Definition

Member function can be defined in two ways:

(i) Inside the class

(ii) Outside the class

Inside the class: When a member function is defined inside a class, it is considered to be inline by default. If a member function is very small, then it should be defined inside the class.

The class declaration of previous program will be as follow:


Nesting of Member Functions

A member function can be called by using its name inside another member function of the same class. This is known as nesting of member functions.

The following program illustrates this concept.


Developed by: