Anda di halaman 1dari 11

Constructor

and
Destructor in
Inheritance in
C++
Constructor and Destructor in Inheritance in
Dr. Munesh C++
Singh

Dr. Munesh Singh

Indian Institute of Information Technology


Design and Manufacturing,
Kancheepuram
Chennai-600127

January 20, 2019


Questions

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh

We know that constructor is invoked implicitly when an


object is created.
In inheritance, when we create object of derived class,
what will happen?
Constructor Call

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh
Default Parametrize Constructor

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh
Parametrize Constructor

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh
Call and Execustion

Constructor
and
Destructor in Constructor
Inheritance in
C++ Derived class object creation call the derived class
Dr. Munesh
Singh
constructor at first, but execute the parent class
constructor at first
If we not defined any constructor in a program, the
compiler include the code for constructor

Disctructor
Derived class object creation call the derived class
constructor at first, but execute the parent class
constructor at first
If we not defined any constructor in a program, the
compiler include the code for constructor
Distructor Call

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh
This Pointer in C++

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh A pointer contains address of an object is called Object
pointer.
Object Pointer Use

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh
this Pointer

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh

this is a keyword
this is a local object pointer in every instance member
function containing address of the caller object.
this pointer can not be modify
It is used to refer caller object in member function
this pointer use

Constructor
and
Destructor in
Inheritance in
C++

Dr. Munesh
Singh

Anda mungkin juga menyukai