0% found this document useful (0 votes)
99 views

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

The document discusses constructors and destructors in inheritance in C++. It notes that when a derived class object is created, the derived class constructor is called first but the parent class constructor is executed first. It also discusses that if no constructor is defined, the compiler includes a default constructor. Additionally, it states that destructors are called in the reverse order of constructors, with the parent class destructor called first. The document also covers the use of the "this" pointer to refer to the caller object within member functions.

Uploaded by

MUNESH SINGH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

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

The document discusses constructors and destructors in inheritance in C++. It notes that when a derived class object is created, the derived class constructor is called first but the parent class constructor is executed first. It also discusses that if no constructor is defined, the compiler includes a default constructor. Additionally, it states that destructors are called in the reverse order of constructors, with the parent class destructor called first. The document also covers the use of the "this" pointer to refer to the caller object within member functions.

Uploaded by

MUNESH SINGH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like