You are on page 1of 6

Object Oriented

Programming
MUHAMMAD IRTAZA SALEEM
This Pointer ->
Every object in C++ has access to its own address through an
important pointer called this pointer.
The this pointer is an implicit parameter to all member
functions. Therefore, inside a member function, this may be
used to refer to the invoking object.

Friend functions do not have a this pointer, because friends


are not members of a class.
Only member functions have a this pointer.
Why use This Pointer ?
A common explicit use of the this
pointer is to avoid naming conflicts
between a class’s data members and
member-function parameters (or
other local variables).
Let’s do some practice
- Create Box Class
- Parameterized Constructor
- Create Volume Function as member function
- Create a Compare_volume Function as member,
which compares the volume of two boxes, and
returns the Volume of greater object.

- Prints the greater Volume in Main function


Cascaded Function Call in C++
Using this Pointer to Enable Cascaded Function Calls

C++ programming allows calling functions like this, when multiple functions called using a single
object name in a single statement, it is known as cascaded function call in C++.

obj.FUN1().FUN2().FUN3();
Let’s do some practice
- Create Box Class

- Non-Parametrized Constructor

- Create individual setter functions for (L,W,H)

- Using a single statement in main function, invoke


all the setter functions.

- Create a print Volume Function which displays the


volume of Function.

You might also like