Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

Object Oriented

Programming (CC-211-3)
Instructor: Abdullah Javed
(muhammad.abdullah@pujc.edu.pk)
Visiting Lecturer,
Punjab University, Jhelum Campus.

Lecture 04.1
Fall 2021
TODAY’S AGENDA
• The this pointer

2
this pointer
• Object's member functions can manipulate the object's data
• How do member functions know which object's data members to
manipulate?
• Every object has access to its own address through a pointer called
this
• this pointer is passed (by the compiler) as an implicit argument to
each of the object's non-static member functions

3
Cont.
• An object's this pointer is not part of the object itself
• Objects use this pointer implicitly or explicitly to reference their data
members and member functions

4
Type of this pointer
• The type of the this pointer depends on the type of the object
• non constant member function of class Employee, the this pointer has type
Employee * const
• constant member function of the class Employee, the this pointer has the
data type const Employee * const

5
Implicitly and Explicitly Use this Pointer

You might also like