<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}
.topnav {
  overflow: hidden;
  background-color: #f2f2f2;
}
.topnav a {
  float: left;
  color: #000080;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size:20px;
}

.topnav a:hover {
  background-color: #ddd ;
  color: black;
}

.topnav a.active {
  background-color:#000080  ;
  color:white;
}

header, footer {
    padding: 1em;
    color: white;
    background-color: #000080;
    clear: left;
    font-size:large;
    text-align: center;
}

nav {
    float: left;
    max-width: 180px;
    margin: 0;
    padding: 1em;
}

nav ul {
    list-style-type: none;
    padding: 0;
    font-size:20px;
}

nav ul a {
    text-decoration: none;
}

article {
    margin-left: 170px;
    border-left: 1px solid gray;
    padding: 1em;
    overflow: hidden;
} 
.icon-bar a {
    float: left;
    width: 5%;
    text-align: center;
    padding: 13px 0;
    color: #000080;
    font-size: 25px;
}
.vertical-menu {
    width: 180px;
}

.vertical-menu a {
    background-color:#eee;
    color:black;
    display: block;
    padding:15px;
    text-decoration: none;
}

.vertical-menu a:hover {
    background-color: #ccc;
}

.vertical-menu a.active {
    background-color: #000080;
    color: white;
}
a{
    text-decoration: none;
    display: inline-block;
    padding: 9px 17px;
}

a:hover {
    background-color: #ddd;
    color: black;
}

.previous {
    background-color:#000080;
    color: white;
}

.next {
    background-color: #000080;
    color: white;
	margin-left:780px;
}

</style>

</head>
<body>
<header>
<h1>CPP Programming</h1>
</header>

<div class="topnav">
  <div class="icon-bar"> <a class="" href="index.html"><i class="fa fa-home"></i></a> </div>
<a href="allprolang.html">All Languages</a>
  <a href="c_overview.html">C</a>
  <a class="active" href="cpp_overview.html">CPP</a>
  <a href="java_overview.html">JAVA</a>
  <a href="html_overview.html">HTML</a>
  <a href="css_overview.html">CSS</a>
  <a href="javascript_overview.html">JAVASCRIPT</a>
  <a href="python_overview.html">PYTHON</a>
  <div class="icon-bar"> <a class="" href="#"><i class="fa fa-search"></i></a> </div></div>
<nav>
<div class="vertical-menu">
<a href="cpp_overview.html">Overview</a>
<a href="cpp_envrnmnt.html">Environment Setup</a>
<a href="cpp_basicsyntax.html">Basic Syntax</a>
<a href="cpp_comments.html">Comments</a>
<a href="cpp_datatypes.html">Data types</a>
<a href="cpp_variables.html">Variable Types</a>
<a href="cpp_constliterals.html">Constants &literas </a>
<a href="cpp_modifiertypes.html">Modifier Types</a>
<a href="cpp_storageclasses.html">Storage Classes</a>
<a href="cpp_operators.html">Operators</a>
<a href="cpp_loops.html">Loops</a>
<a href="cpp_decisionmake.html">Decision Making</a>
<a href="cpp_functions.html">Functions</a>
<a href="cpp_arraays.html">Arrays</a>
<a href="cpp_strings.html">Strings</a>
<a href="cpp_pointers.html">Pointers</a>
<a href="cpp_references.html">References</a>
<a href="cpp_basicio.html">Basic Input&Output </a>
<a href="cpp_datastructures.html">Data Structures</a>
<a href="cpp_classobject.html">Classes&Objects </a>
<a href="cpp_inheritance.html">Inheritance </a>
<a class="active" href="cpp_overloading.html">Overloading</a>
<a href="cpp_polymorphism.html">Polymorphism</a>
<a href="cpp_encapsulation.html">Encapsulation</a>
<a href="cpp_interfaces.html">Interfaces</a> 
</div> </nav>

<article>
<a href="cpp_inheritance.html" class="previous">&laquo; Previous</a>
<a href="cpp_polymorphism.html" class="next">Next &raquo;</a>
<h1 style="color:#000080">Oerloading(Function and Operator) In Cpp</h1>
<p>If we create two or more members having same name but different in number or type of parameter, it is known as C++ overloading. In C++, we can overload:

methods,
constructors, and
indexed properties
It is because these members have parameters only.</p>

<h3>Types of overloading in C++ are:</h3>

<ul><li>Function overloading</li>
<li>Operators overloading</li></ul>
<h3>C++ Function Overloading</h3>
<p>Having two or more function with same name but different in parameters, is known as function overloading in C++.<br>

The advantage of Function overloading is that it increases the readability of the program because you don't need to use different names for same action.</p>

<h3>C++ Function Overloading Example:</h3>

<p>Let's see the simple example of function overloading where we are changing number of arguments of add() method.</p>
<table border="" width="500"><tr><td><pre>
#include &ltiostream&gt  
using namespace std;  
class Cal {  
    public:  
static int add(int a,int b){    
        return a + b;    
    }    
static int add(int a, int b, int c)    
    {    
        return a + b + c;    
    }    
};   
int main(void) {  
    Cal C;  
    cout&lt&ltC.add(10, 20)&lt&ltendl;    
    cout&lt&ltC.add(12, 20, 23);   
   return 0;  
}  </tr></td></pre></table><br>
<b>Output:</b>
<table border="" width="500"><tr><td><pre>
30
55
</table></tr></td></pre>

 
<h3>C++ Operators Overloading</h3>
<p>Operator overloading is used to overload or redefine most of the operators available in C++. It is used to perform operation on user define data type.<br>

The advantage of Operators overloading is to perform different operations on the same operand.</p>

<h3>C++ Operators Overloading Example</h3>
<p>Let's see the simple example of operator overloading in C++. In this example, void operator ++ () operator function is defined (inside Test class).</p>
<table border="" width="500"><tr><td><pre>
#include &ltiostream>  
using namespace std;  
class Test  
{  
   private:  
      int num;  
   public:  
       Test(): num(8){}  
       void operator ++()   
       {   
          num = num+2;   
       }  
       void Print() {   
           cout&lt&lt"The Count is: "&lt&ltnum;   
       }  
};  
int main()  
{  
    Test tt;  
    ++tt;  // calling of a function "void operator ++()"  
    tt.Print();  
    return 0;  
}  </tr></td></pre></table><br>
<b>Output:</b>
<table border="" width="500"><tr><td><pre>
The Count is: 10</table></tr></td></pre><br><br>
<a href="cpp_inheritance.html" class="previous">&laquo; Previous</a>
<a href="cpp_polymorphism.html" class="next">Next &raquo;</a>
</article>
<footer>Devoloped by LE's</footer>
</div>
</body>
</html>