Chapter 4
Chapter 4
Chapter 4
Advantages:
Does not require function calling overhead.(i.e Reduction in Function Call
Overhead)
Saves time
Less execution time(i.e faster execution of code.)
Disadvantage/Limitations:
Requires more memory.
2. Write a program to calculate the volume of different shapes like cube, cylinder
and sphere and
hence implement the concept of function overloading.
#include <iostream>
using namespace std;
const double PI = 3.142;
// Volume of a cylinder
cout << "\nVolume of the cylinder: " <<
Volume(radius, height);
// Volume of a spher
cout << "\nVolume of the sphere: " <<
Volume(radius) ;
return 0;
}
A friend function is not a member function of the class for which it is declared as
a friend.
Can Access Private and Protected Members:
A friend function has the privilege to access the private and protected members of
the class for which it is a friend.
Declared Inside the Class:
The declaration of a friend function is done inside the class using the friend
keyword.