0% found this document useful (0 votes)
68 views31 pages

Function Overloading and Overriding in C++: March 22, 2013

This document discusses function overloading and overriding in C++. It begins by outlining the learning objectives, which are to understand function overloading, function overriding, and demonstrate them with examples. It then defines function overloading as having multiple functions with the same name but different arguments or return types. Function overriding is redefining a base class function in a derived class, where the arguments and return type must be the same. The key differences between overloading and overriding are also outlined.

Uploaded by

prajari ghosh
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)
68 views31 pages

Function Overloading and Overriding in C++: March 22, 2013

This document discusses function overloading and overriding in C++. It begins by outlining the learning objectives, which are to understand function overloading, function overriding, and demonstrate them with examples. It then defines function overloading as having multiple functions with the same name but different arguments or return types. Function overriding is redefining a base class function in a derived class, where the arguments and return type must be the same. The key differences between overloading and overriding are also outlined.

Uploaded by

prajari ghosh
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/ 31

Function Overloading and

Overriding in C++
Talk to a Teacher
http://spoken-tutorial.org
National Mission on Education through ICT
http://sakshat.ac.in
Ashwini R Patil
IIT Bombay
5 December 2012
Ashwini R Patil Function Overloading and Overriding in C++
Learning Objectives

Ashwini R Patil Function Overloading and Overriding in C++


Learning Objectives

I Function Overloading

Ashwini R Patil Function Overloading and Overriding in C++


Learning Objectives

I Function Overloading
I Function Overriding

Ashwini R Patil Function Overloading and Overriding in C++


Learning Objectives

I Function Overloading
I Function Overriding
I We will do this with the help of
examples

Ashwini R Patil Function Overloading and Overriding in C++


System Requirements

Ashwini R Patil Function Overloading and Overriding in C++


System Requirements

I Ubuntu OS v. 11.10

Ashwini R Patil Function Overloading and Overriding in C++


System Requirements

I Ubuntu OS v. 11.10
I g++ Compiler v. 4.6.1

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overloading

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overloading

I Function Overloading means two or


more functions can have same name

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overloading

I Function Overloading means two or


more functions can have same name
I The number of arguments and the
data-type of the arguments will be
dierent

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overloading

I Function Overloading means two or


more functions can have same name
I The number of arguments and the
data-type of the arguments will be
dierent
I When a function is called it is selected
based on the argument list
Ashwini R Patil Function Overloading and Overriding in C++
Introduction to function overriding

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overriding

I Redening a base class function in the


derived class

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overriding

I Redening a base class function in the


derived class
I The derived class function overrides the
base class function

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overriding

I Redening a base class function in the


derived class
I The derived class function overrides the
base class function
I But the arguments passed are same

Ashwini R Patil Function Overloading and Overriding in C++


Introduction to function overriding

I Redening a base class function in the


derived class
I The derived class function overrides the
base class function
I But the arguments passed are same
I And the return-type is also same

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I Overloading can occur without
inheritance

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I Overloading can occur without
inheritance
I Overriding occurs when one class is
inherited from another

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I Overloading can occur without
inheritance
I Overriding occurs when one class is
inherited from another
I In overloading the arguments and the
return-type must dier

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I Overloading can occur without
inheritance
I Overriding occurs when one class is
inherited from another
I In overloading the arguments and the
return-type must dier
I In overriding the arguments and the
return type must be same
Ashwini R Patil Function Overloading and Overriding in C++
Dierence
I In overloading the function name is
same

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I In overloading the function name is
same
I But it behaves dierently depending on
the arguments passed to them

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I In overloading the function name is
same
I But it behaves dierently depending on
the arguments passed to them
I In overriding the function name is same

Ashwini R Patil Function Overloading and Overriding in C++


Dierence
I In overloading the function name is
same
I But it behaves dierently depending on
the arguments passed to them
I In overriding the function name is same
I Derived class function can perform
dierent operations from the base class

Ashwini R Patil Function Overloading and Overriding in C++


Summary
I Function overloading
I eg. int add(int, int, int);
oat add(oat, oat);
I Function Overriding
I eg. virtual int operations()
int operations()
I Dierence between both
Ashwini R Patil Function Overloading and Overriding in C++
Assignment

I Write a program that will calculate the


area of rectangle, square and circle
I Using function overloading

Ashwini R Patil Function Overloading and Overriding in C++


About the Spoken Tutorial Project

I Watch the video available at


http://spoken-tutorial.org
/What_is_a_Spoken_Tutorial
I It summarises the Spoken Tutorial
project

Ashwini R Patil Function Overloading and Overriding in C++


About the Spoken Tutorial Project

I Watch the video available at


http://spoken-tutorial.org
/What_is_a_Spoken_Tutorial
I It summarises the Spoken Tutorial
project
I If you do not have good bandwidth,
you can download and watch it
Ashwini R Patil Function Overloading and Overriding in C++
Spoken Tutorial Workshops
The Spoken Tutorial Project Team
I Conducts workshops using spoken

tutorials
I Gives certicates to those who pass an

online test
I For more details, please write to

[email protected]

Ashwini R Patil Function Overloading and Overriding in C++


Acknowledgements
I Spoken Tutorial Project is a part of the
Talk to a Teacher project
I It is supported by the National Mission
on Education through ICT, MHRD,
Government of India
I More information on this Mission is
available at:
http://spoken-tutorial.org
/NMEICT-Intro
Ashwini R Patil Function Overloading and Overriding in C++

You might also like