{"id":29771,"date":"2023-11-08T09:10:39","date_gmt":"2023-11-08T03:40:39","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/"},"modified":"2025-01-06T19:31:03","modified_gmt":"2025-01-06T14:01:03","slug":"function-overloading-in-cpp","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/","title":{"rendered":"Function Overloading in C++ With Examples"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-function-overloading-in-c\"><strong>What is Function Overloading in C++?&nbsp;&nbsp;&nbsp;<\/strong><\/h2>\n\n\n\n<p>Two or more functions can have the same name but different parameters; such functions are called function overloading in c++. The function overloading in the c++ feature is used to improve the readability of the code. It is used so that the programmer does not have to remember various function names. If any class has multiple functions with different parameters having the same name, they are said to be overloaded. If we have to perform a single operation with different numbers or types of arguments, we need to overload the function.<strong>&nbsp;&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p>If I say parameter list, it means the data type and sequence of the parameters. For example, the parameters list of a function myfunction (int a, double b) is (int, double), which is different from the function myfunction (double a, int b) parameter list (double, int). Function overloading is a compile-time polymorphism. As we already know what a parameter list is, so let\u2019s see the rules of overloading: we can have the following functions in the same scope.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>sum(int a, int b)\nsum(int a, int b, int c)\n<\/code><\/pre>\n\n\n\n<p>The easiest way to remember this rule is that the parameters should qualify any one or more than one of the following conditions:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>They should have a different type<\/li>\n\n\n\n<li>They should have a different number&nbsp;<\/li>\n\n\n\n<li>They should have a different sequence of parameters.<\/li>\n<\/ul>\n\n\n\n<p>To put it simply,<\/p>\n\n\n\n<p>Function overloading in c++ can have the same name but different parameters<\/p>\n\n\n\n<p>C++ has many features, and one of the most important features is function overloading. It is a code with more than one function with the same name having various types of argument lists. This argument list includes the data type of arguments and the sequence of the arguments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"function-overloading-in-c-example\"><strong>Function Overloading in C++ Example <\/strong><\/h2>\n\n\n\n<p>Example 1: <\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nvoid SumNum(int A, int B);\nvoid SumNum(int A, int B, int C);\nvoid SumNum(int A, int B, int C, int D);\n\nint main()\n{\n    SumNum(1,2);\n    SumNum(1,2,3);\n    SumNum(1,2,3,4);\n    \n    return 0;\n}\n\nvoid SumNum(int A, int B)\n{\n     cout&lt;&lt; endl &lt;&lt; \"SUMNUM is : \"&lt;&lt; A+B;     \n}\n\nvoid SumNum(int A, int B, int C)\n{\n     cout&lt;&lt; endl &lt;&lt; \"SUMNUM is : \"&lt;&lt; A+B+C;  \n}\n\nvoid SumNum(int A, int B, int C, int D)\n{\n     cout&lt;&lt; endl &lt;&lt; \"SUMNUM is : \"&lt;&lt; A+B+C+D;     \n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code><strong>Output:\n<\/strong>SumNum is 3\nSumNum is 6\nSumNum is 10\n<\/code><\/pre>\n\n\n\n<p>Example 2: <\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\nclass Addition\n {\n    public:\n    int sum(int a,int b) \n    {\n        return a+b;\n    }\n    int sum(int a,int b, int c) \n    {\n       return a+b+c;\n    }\n };\nint main(void)\n{\n    Addition obj;\n    cout&lt;&lt;obj.sum(20, 15)&lt;&lt;endl;\n    cout&lt;&lt;obj.sum(81, 100, 10);\n    return 0;\n}\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code><strong>Output :\n<\/strong>35\n191<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-is-function-overloading-in-c-is-used\"><strong>Why is function overloading in C++ is used?<\/strong><\/h2>\n\n\n\n<p>Function overloading is similar to polymorphism that helps us to get different behaviour, with the same name of the function. Function overloading in c++ is used&nbsp;for code reusability and to save memory. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rules-of-function-overloading-in-c\"><strong>Rules&nbsp;of Function Overloading in C++<\/strong><\/h2>\n\n\n\n<p>Different parameters or three different conditions :<\/p>\n\n\n\n<p><strong>1.&nbsp; These&nbsp; functions have different parameter type<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>sum(int a, int b)\nsum(double a, double b)\n<\/code><\/pre>\n\n\n\n<p><strong>2. &nbsp; These functions have a different number of parameters<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>sum(int a, int b)\nsum(int a, int b, int c)\n<\/code><\/pre>\n\n\n\n<p><strong>3.&nbsp; These functions have a different sequence of parameters<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>sum(int a, double b)\nsum(double a, int b)\n<\/code><\/pre>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>The above three cases are valid cases of overloading. We can have any number of functions, but remember that the parameter list must be different. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int mul(int, int)\ndouble mul(int, int)\n<\/code><\/pre>\n\n\n\n<p>As the parameter list is the same, this is not allowed. Even though their return types are different, it\u2019s not valid.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-difference-between-function-overloading-and-overriding-in-c\"><strong>What is the difference between function overloading and overriding in C++?<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><\/td><td><strong>Function Overloading<\/strong><\/td><td><strong>Function Overriding<\/strong><\/td><\/tr><tr><td>Definition<\/td><td>When two or more methods in a class have distinct parameters but the same method name, this is known as function overloading.<\/td><td>One method is in the parent class and the other is in the child class when a function is overridden, but they have the same parameters and method name.<\/td><\/tr><tr><td>Function signature<\/td><td>There should be a difference in the number or kind of parameters.<\/td><td>The function signature should not change.<\/td><\/tr><tr><td>Behaviour<\/td><td>defines several methods' behaviours.<\/td><td>changes the way the procedure behaves.<\/td><\/tr><tr><td>Scope of Function<\/td><td>They belong to the same category.<\/td><td>They have a distinct range.<\/td><\/tr><tr><td>Inheritance<\/td><td>Even without inheritance, it can happen.<\/td><td>Only when a class inherits from another does it happen<\/td><\/tr><tr><td>Polymorphism<\/td><td>Compile Time<\/td><td>Run Time<\/td><\/tr><tr><td>Technique<\/td><td>code improvement method.<\/td><td>method for replacing code.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"function-overloading-and-ambiguity\"><strong>Function overloading and ambiguity<\/strong><\/h2>\n\n\n\n<p>The C++ programming language offers an overloading feature that enables an overload of two or more methods with the same name but distinct parameters in order to create compile-time polymorphism. Function and operator overloading can be used to carry it out. While operator overloading overloads operators to provide user-defined data types with particular meaning, function overloading overloads two or more functions with the same name but distinct parameters.<\/p>\n\n\n\n<p>Using built-in operators on user-defined types is made possible by this feature. Operator overloading makes the code easier to understand by redefining the functionality to meet user needs. Both function overloading and operator overloading will be discussed in detail as well as how they are applied in C++ in this article.<\/p>\n\n\n\n<p>Using the Overloading idea, C++ enables the creation of flexible and understandable code. It enables adding different functionality to the existing code with a minimum number of changes, hence minimising the need for duplicate code. Practically speaking, C++ allows two basic types of overloading.<\/p>\n\n\n\n<p>Function Overloading, a feature of C++, allows us to create functions with the same name but different datatypes or numbers of arguments supplied to them. Developers can define functions with the same name within the same scope thanks to this capability. The functions that have a name also share the same behaviour, enabling compile-time polymorphism. One benefit of function overloading is that it makes the code easier to read.<\/p>\n\n\n\n<p>The use of arguments can be used in any way to create function overloading. Usage of parameters might refer to a particular parameter type, a parameter count, or a parameter sequence. As a result, a function defined as calc (float x, int y) is different from calc (int x, float y), which has separate parameters with a different datatype.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-function-overloading-in-c\"><strong>Types of function overloading in c++ <\/strong><\/h2>\n\n\n\n<p>There are two types of function overloading in c++- <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Compile time overloading<\/strong>- In compile time overloading, functions are overloaded using different signatures. Signature of a function includes its return type, number of parameters and types of parameters. <\/li>\n\n\n\n<li><strong>Runtime overloading<\/strong> -In runtime overloading, functions are overloaded using a different number of parameters.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"causes-of-function-overloading-in-c\"><strong>Causes of function overloading in c++<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Type Conversion.<\/li>\n\n\n\n<li>Function with default arguments.<\/li>\n\n\n\n<li>Function with a pass-by reference.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-type-conversion\"><strong>1. Type Conversion <\/strong><\/h3>\n\n\n\n<p><strong>Program :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream&gt;\nusing namespace std;\nvoid function(float);\nvoid function(int);\nvoid function(float x)\n{\nstd::cout &lt;&lt; \"Value of x is : \" &lt;&lt;x&lt;&lt; std::endl;\n}\nvoid function(int y)\n{\nstd::cout &lt;&lt; \"Value of y is : \" &lt;&lt;y&lt;&lt; std::endl;\n}\nint main()\n{\nfunction(3.4);\nfunction(34);\nreturn 0;\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>This example shows an error \u201ccall of overloaded \u2018function\u2019 is ambiguous\u201d. According to our prediction, function (3.4) will call the first function, and function (34) will call the second function. But this is not what happens because, in C++, all the floating-point constants are not treated as float; instead, they are treated as double.&nbsp; If we replace the float variable with a double variable, the program will work properly. Thus we call it a type conversion error from float to double.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-function-with-default-arguments\"><strong>2. Function with Default Arguments<\/strong><\/h3>\n\n\n\n<p><strong>Program :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream&gt;\nusing namespace std;\nvoid function(int);\nvoid function(int,int);\n\nvoid function(int x)\n{\nstd::cout &lt;&lt; \"Value of x is : \" &lt;&lt;x&lt;&lt; std::endl;\n}\nvoid function(int y,int z=12)\n{\nstd::cout &lt;&lt; \"Value of y is : \" &lt;&lt;y&lt;&lt; std::endl;\nstd::cout &lt;&lt; \"Value of z is : \" &lt;&lt;z&lt;&lt; std::endl;\n}\nint main()\n{\nfunction(12);\nreturn 0;\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The above example shows an error saying \u201ccall of overloaded \u2018fun(int)\u2019 is ambiguous\u201d, this is because function(int y, int z=12) can be called in two ways:<\/p>\n\n\n\n<p>By calling the function with only one argument (and it will automatically take the value of z = 12)<\/p>\n\n\n\n<p>By calling the function with only two arguments.<\/p>\n\n\n\n<p>When you call the function: function(12), we full fill the condition of both function(int) and function(int, int); therefore, the compiler gets into an ambiguity that gives an error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-function-with-a-pass-by-reference\"><strong>3. Function with a Pass by Reference<\/strong><\/h3>\n\n\n\n<p><strong>Program :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nusing namespace std;\nvoid function(int);\nvoid function(int &amp;);\nvoid function(int a)\n{\nstd::cout &lt;&lt; \"Value of a is : \" &lt;&lt;a&lt;&lt; std::endl;\n}\nvoid function(int &amp;b)\n{\nstd::cout &lt;&lt; \"Value of b is : \" &lt;&lt;b&lt;&lt; std::endl;\n}\n\nint main()\n{\nint x=10;\nfunction(x);\nreturn 0;\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The above program shows an error saying \u201ccall of overloaded \u2018fun(int&amp;)\u2019 is ambiguous\u201d. As we see, the first function takes one integer argument, and the second function takes a reference parameter as an argument. In this case, the compiler cannot understand which function is needed by the user as there is no syntactic difference between the fun(int) and fun(int &amp;); therefore, it shoots an error of ambiguity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"overloading-using-different-types-of-parameters\"><strong>Overloading using different types of parameters<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nvoid printValue(int   A);\nvoid printValue(char  A);\nvoid printValue(float A);\n\nint main()\n{\n    printValue(10     );\n    printValue('@'    );\n    printValue(3.14f  );\n\n    return 0;\n}\n\nvoid printValue(int   A)\n{\n     cout&lt;&lt; endl &lt;&lt; \"Value of A : \"&lt;&lt; A;     \n}\n\nvoid printValue(char  A)\n{\n     cout&lt;&lt; endl &lt;&lt; \"Value of A : \"&lt;&lt; A;     \n}\n\nvoid printValue(float A)\n{\n     cout&lt;&lt; endl &lt;&lt; \"Value of A : \"&lt;&lt; A;     \n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>Output:\nValue of A : 10\nValue of A : @\nValue of A : 3.14\n<\/code><\/pre>\n\n\n\n<p>Function overloading can be implemented based on the many types of arguments that are passed into the function. Both non-member functions and member functions of a class may implement function overloading.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"function-overloading-by-changing-the-number-of-arguments\"><strong>Function overloading by changing the number of arguments <\/strong><\/h3>\n\n\n\n<p>On the basis of the quantity of parameters supplied into the function, we can implement function overloading. Both non-member functions and member functions of a class may implement function overloading<strong>.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nvoid SumNum(int A, int B);\nvoid SumNum(int A, int B, int C);\nvoid SumNum(int A, int B, int C, int D);\n\nint main()\n{\n    SumNum(1,2);\n    SumNum(1,2,3);\n    SumNum(1,2,3,4);\n    \n    return 0;\n}\n\nvoid SumNum(int A, int B)\n{\n     cout&lt;&lt; endl &lt;&lt; \"SUMNUM is : \"&lt;&lt; A+B;     \n}\n\nvoid SumNum(int A, int B, int C)\n{\n     cout&lt;&lt; endl &lt;&lt; \"SUMNUM is : \"&lt;&lt; A+B+C;     \n}\n\nvoid SumNum(int A, int B, int C, int D)\n{\n     cout&lt;&lt; endl &lt;&lt; \"SUMNUM is : \"&lt;&lt; A+B+C+D;     \n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code><strong>Output:\n<\/strong>SumNum is 3\nSumNum is 6\nSumNum is 10\n\n<\/code><\/pre>\n\n\n\n<p>In this way of function overloading, we define two functions of the same type but with a different number of parameters with the same names. For example, in the program given below, we have made two add() functions to return the sum of two and three integers.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>\/\/ first function definition\nint add(int a, int b)\n{\ncout &lt;&lt; a+b;\n}\n\/\/ second overloaded function definition\nint add(int a, int b, int c)\n{\ncout &lt;&lt; a+b+c;\n}\n<\/code><\/pre>\n\n\n\n<p>Here add() function is said to be overloaded, as it has two definitions, one that can accept two arguments and another which can accept three arguments. Which add() function will be called, depending on the number of arguments.<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>int main() \n{ \nadd(10, 20); \/\/ add() with 2 parameter     \nadd(10, 20, 30); \/\/sum() with 3 parameter \n}\n<\/code><\/pre>\n\n\n\n<p><strong>Program ( By changing the number of arguments):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\nint add(int a, int b)\n{\ncout &lt;&lt; a+b &lt;&lt;endl;\nreturn 0;\n}\nint add(int a, int b, int c)\n{\ncout &lt;&lt; a+b+c &lt;&lt;endl;\nreturn 0;\n}\nint main()\n{\nadd(20, 40);\nadd(40, 20, 30);\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code><strong>Output:\n<\/strong>60 \n90<\/code><\/pre>\n\n\n\n<p>In the above example, we overload an add() function by changing the number of arguments. First, we define an add() function with the two parameters, and then we can overload it by again defining an add() function but this time with three parameters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"function-overloading-by-different-types-of-arguments\"><strong>Function overloading by different types of arguments<\/strong><\/h3>\n\n\n\n<p>In this method, we define two or more functions with the parameters of different data types but with the same number of parameters with the same name. For example, in this program, we have three add() functions; the first one will get two integer arguments, the second one will get two float arguments, and the third one will get two double arguments.<\/p>\n\n\n\n<p><strong>Program :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code>#include &lt;iostream&gt;\nusing namespace std;\nint add(int x, int y) \/\/ first definition\n{\ncout&lt;&lt; x+y &lt;&lt; endl;\nreturn 0;\n}\nfloat add(float a, float b)\n{\ncout &lt;&lt; a+b &lt;&lt; endl;\nreturn 0;\n}\ndouble add(double x, double y)\n{\ncout &lt;&lt; x+y &lt;&lt; endl;\nreturn 0;\n}\nint main()\n{\nadd(20, 40);\nadd(23.45f, 34.5f);\nadd(40.24, 20.433);\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background\"><code><strong>Output :<\/strong>\n60\n57.95\n60.673\n<\/code><\/pre>\n\n\n\n<p>In the above example, we define an add() function three times. First, using integers as parameters, secondly, using float as parameters, and third using double as a parameter.<\/p>\n\n\n\n<p>Therefore we override the add() function twice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advantages-of-function-overloading-in-c\"><strong>Advantages of Function Overloading in c++<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The program is very simple and also easier to understand.<\/li>\n\n\n\n<li>It saves the memory space, maintains consistency, makes clear interface for methods regardless of the parameter\u2019s type and readability of the program.<\/li>\n\n\n\n<li>Using the function overloading concept, we can develop more than one function with the same name, but the arguments passed should be of different types.<\/li>\n\n\n\n<li>Function overloading executes the program faster.<\/li>\n\n\n\n<li>Function overloading is used for code reusability and to save memory.<\/li>\n<\/ul>\n\n\n\n<p><em><em>To understand function overloading in C++ clearly, you must be well-versed in C++. If you wish to enhance your skills, you can take up the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/introduction-to-c\" target=\"_blank\">Introduction to C++ free course<\/a> at Great Learning Academy and learn the basic concepts and fundamentals of C++ to help you build expertise in the subject.&nbsp;<\/em><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"disadvantages-of-function-overloading-in-c\"><strong>Disadvantages of Function Overloading in c++<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Function declarations that differ by their return type cannot be overloaded with the function overloading process.<\/li>\n\n\n\n<li>If any static member function is declared, then the same parameters or the same name types cannot be overloaded.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"difference-between-function-overloading-and-operator-overloading\"><strong>Difference between Function Overloading and Operator Overloading<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-stripes\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Function Overloading<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Operator Overloading<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Function overloading allows us to call it in multiple ways.<\/td><td class=\"has-text-align-center\" data-align=\"center\">Operator overloading allows operators to have their extending meaning beyond its predefined operational meaning.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">You can overload the function with the same name but with different parameters.<\/td><td class=\"has-text-align-center\" data-align=\"center\">You can overload (define custom behaviour) for operators such as '+', '-', '()', '[]'.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Function overloading means using a single name and giving more functionality to it.<\/td><td class=\"has-text-align-center\" data-align=\"center\">Operator overloading means adding extra functionality for a certain operator.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">When an operator is overloaded, the operator has different meanings, which depend on the type of its operands.<\/td><td class=\"has-text-align-center\" data-align=\"center\">When a function is overloaded, the same function name has different interpretations depending on its signature, which is the list of argument types in the functions parameter list.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If you want to learn more about operator overloading visit <a href=\"https:\/\/www.mygreatlearning.com\/blog\/operator-overloading-in-cpp\/\" data-type=\"URL\" data-id=\"https:\/\/www.mygreatlearning.com\/blog\/operator-overloading-in-cpp\/\" target=\"_blank\" rel=\"noreferrer noopener\">Operator Overloading in C++<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"difference-between-function-overloading-and-function-overriding\"><strong>Difference between Function Overloading and Function Overriding<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>&nbsp;<\/td><td>Function Overloading<\/td><td>Function Overriding<\/td><\/tr><tr><td>Definition<\/td><td>In function overloading, two or more methods in one class have different parameters but the same method name.<\/td><td>In function overriding, two methods have the same parameters, and method name, but one method is in the parent class and the other is in the child class.<\/td><\/tr><tr><td>Function Signature<\/td><td>Either type of parameters or the number of parameters should differ.<\/td><td>Function signature should remain the same.<\/td><\/tr><tr><td>Behavior<\/td><td>Defines multiple behaviors to a method.<\/td><td>Changes the behavior of the method.<\/td><\/tr><tr><td>Scope of Function<\/td><td>They are in the same scope.<\/td><td>They are in different scope.<\/td><\/tr><tr><td>Inheritance<\/td><td>It can occur without inheritance.<\/td><td>It occurs only when one class is inherited from another class.<\/td><\/tr><tr><td>Polymorphism<\/td><td>Compile Time<\/td><td>Run Time<\/td><\/tr><tr><td>Technique<\/td><td>Code refinement technique<\/td><td>Code replacement technique<\/td><\/tr><tr><td>No. of Classes<\/td><td>Only one class is required.<\/td><td>Minimum two classes are required.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"function-overloading-in-c-faqs\"><strong>Function overloading in C++ FAQs<\/strong><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1662972969125\"><strong class=\"schema-faq-question\"><strong>What is function overloading in C++?<\/strong><br\/><\/strong> <p class=\"schema-faq-answer\">Function overloading refers to when two or more functions with the same name but distinct parameters exist.<br\/>Function overloading is one of the most crucial characteristics of C++, among its many other features. There are many functions with the same name in this code, each with a unique set of argument lists. The data type and ordering of the arguments are also included in this argument list.<br\/>The C++ function overloading feature is used to make the code easier to read. It is used to save the programmer from having to memorise different function names. Overloaded functions are those that belong to a class but have more than one instance with the same name but different parameters. The function must be overloaded if a single operation must be performed with various numbers or types of parameters.<br\/>Function overloading is referred to as a function of polymorphism in OOP.<br\/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662972993852\"><strong class=\"schema-faq-question\"><strong>What is function overloading explain?<\/strong><\/strong> <p class=\"schema-faq-answer\">Similar to polymorphism, function overloading enables us to obtain different behaviour while maintaining the function's name. In C++, function overloading is used to reduce memory usage and increase code reuse.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662973036790\"><strong class=\"schema-faq-question\"><strong>What is runtime polymorphism C++?<\/strong><br\/><\/strong> <p class=\"schema-faq-answer\">Late binding and dynamic polymorphism are other names for runtime polymorphism. The function call is resolved at runtime in runtime polymorphism. In contrast, with compile time or static polymorphism, the compiler determines which function call to bind to the object after deducing it at runtime.<br\/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662973120458\"><strong class=\"schema-faq-question\"><strong>What is inheritance in C++?<\/strong><br\/><\/strong> <p class=\"schema-faq-answer\">By using inheritance, existing classes can be extended and reused without being changed, creating hierarchical links between them. A class can be embedded into an object via inheritance. Let's say you include a class A object of type x in the class specification of type B.<br\/><br\/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1662973131016\"><strong class=\"schema-faq-question\"><strong>What are the advantages of function overloading?<\/strong><\/strong> <p class=\"schema-faq-answer\">The fundamental benefit of function overloading is that it makes code easier to read and reuse.<br\/>Function overloading is used to improve consistency, readability, and memory efficiency.<br\/>The program's execution is accelerated by it.<br\/>Additionally, code upkeep becomes simple.<br\/>Function overloading gives code flexibility.<br\/>The function's versatility avoids the need for many function names to conduct the same set of functions.<\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Function overloading in C++ can be used in different ways to enhance code readability. While doing programming in C++, it helps to save compile time and also saves memory space. You also learned how similar operations are performed using the function overloading concept. After mastering topics like function overloading in C++, you can continue to build your expertise with various <a href=\"https:\/\/www.mygreatlearning.com\/academy\">free courses<\/a> that offer certificates in different programming languages<\/p>\n\n\n\n<p>You can enhance your function overloading in c++ concepts here:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Introduction to C++ | C++ Tutorial For Beginners | Great Learning\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/Qu-QSnFYLZE?start=10&feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>What is Function Overloading in C++?&nbsp;&nbsp;&nbsp; Two or more functions can have the same name but different parameters; such functions are called function overloading in c++. The function overloading in the c++ feature is used to improve the readability of the code. It is used so that the programmer does not have to remember various [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":29775,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[],"content_type":[],"class_list":["post-29771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Function Overloading in C++<\/title>\n<meta name=\"description\" content=\"Function overloading in c++: This can be defined as a function that has the same name but different parameters.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Function Overloading in C++ With Examples\" \/>\n<meta property=\"og:description\" content=\"Function overloading in c++: This can be defined as a function that has the same name but different parameters.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-08T03:40:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-06T14:01:03+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"313\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Function Overloading in C++ With Examples\",\"datePublished\":\"2023-11-08T03:40:39+00:00\",\"dateModified\":\"2025-01-06T14:01:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/\"},\"wordCount\":2445,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_1564856881-1.jpg\",\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/\",\"name\":\"Function Overloading in C++\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_1564856881-1.jpg\",\"datePublished\":\"2023-11-08T03:40:39+00:00\",\"dateModified\":\"2025-01-06T14:01:03+00:00\",\"description\":\"Function overloading in c++: This can be defined as a function that has the same name but different parameters.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662972969125\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662972993852\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973036790\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973120458\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973131016\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_1564856881-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/shutterstock_1564856881-1.jpg\",\"width\":500,\"height\":313,\"caption\":\"function overloading in c\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Function Overloading in C++ With Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662972969125\",\"position\":1,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662972969125\",\"name\":\"What is function overloading in C++?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Function overloading refers to when two or more functions with the same name but distinct parameters exist.<br\\\/>Function overloading is one of the most crucial characteristics of C++, among its many other features. There are many functions with the same name in this code, each with a unique set of argument lists. The data type and ordering of the arguments are also included in this argument list.<br\\\/>The C++ function overloading feature is used to make the code easier to read. It is used to save the programmer from having to memorise different function names. Overloaded functions are those that belong to a class but have more than one instance with the same name but different parameters. The function must be overloaded if a single operation must be performed with various numbers or types of parameters.<br\\\/>Function overloading is referred to as a function of polymorphism in OOP.<br\\\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662972993852\",\"position\":2,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662972993852\",\"name\":\"What is function overloading explain?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Similar to polymorphism, function overloading enables us to obtain different behaviour while maintaining the function's name. In C++, function overloading is used to reduce memory usage and increase code reuse.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973036790\",\"position\":3,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973036790\",\"name\":\"What is runtime polymorphism C++?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Late binding and dynamic polymorphism are other names for runtime polymorphism. The function call is resolved at runtime in runtime polymorphism. In contrast, with compile time or static polymorphism, the compiler determines which function call to bind to the object after deducing it at runtime.<br\\\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973120458\",\"position\":4,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973120458\",\"name\":\"What is inheritance in C++?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"By using inheritance, existing classes can be extended and reused without being changed, creating hierarchical links between them. A class can be embedded into an object via inheritance. Let's say you include a class A object of type x in the class specification of type B.<br\\\/><br\\\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973131016\",\"position\":5,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/function-overloading-in-cpp\\\/#faq-question-1662973131016\",\"name\":\"What are the advantages of function overloading?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The fundamental benefit of function overloading is that it makes code easier to read and reuse.<br\\\/>Function overloading is used to improve consistency, readability, and memory efficiency.<br\\\/>The program's execution is accelerated by it.<br\\\/>Additionally, code upkeep becomes simple.<br\\\/>Function overloading gives code flexibility.<br\\\/>The function's versatility avoids the need for many function names to conduct the same set of functions.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Function Overloading in C++","description":"Function overloading in c++: This can be defined as a function that has the same name but different parameters.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/","og_locale":"en_US","og_type":"article","og_title":"Function Overloading in C++ With Examples","og_description":"Function overloading in c++: This can be defined as a function that has the same name but different parameters.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2023-11-08T03:40:39+00:00","article_modified_time":"2025-01-06T14:01:03+00:00","og_image":[{"width":500,"height":313,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Function Overloading in C++ With Examples","datePublished":"2023-11-08T03:40:39+00:00","dateModified":"2025-01-06T14:01:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/"},"wordCount":2445,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg","articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/","url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/","name":"Function Overloading in C++","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg","datePublished":"2023-11-08T03:40:39+00:00","dateModified":"2025-01-06T14:01:03+00:00","description":"Function overloading in c++: This can be defined as a function that has the same name but different parameters.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662972969125"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662972993852"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973036790"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973120458"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973131016"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg","width":500,"height":313,"caption":"function overloading in c"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Function Overloading in C++ With Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662972969125","position":1,"url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662972969125","name":"What is function overloading in C++?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Function overloading refers to when two or more functions with the same name but distinct parameters exist.<br\/>Function overloading is one of the most crucial characteristics of C++, among its many other features. There are many functions with the same name in this code, each with a unique set of argument lists. The data type and ordering of the arguments are also included in this argument list.<br\/>The C++ function overloading feature is used to make the code easier to read. It is used to save the programmer from having to memorise different function names. Overloaded functions are those that belong to a class but have more than one instance with the same name but different parameters. The function must be overloaded if a single operation must be performed with various numbers or types of parameters.<br\/>Function overloading is referred to as a function of polymorphism in OOP.<br\/>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662972993852","position":2,"url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662972993852","name":"What is function overloading explain?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Similar to polymorphism, function overloading enables us to obtain different behaviour while maintaining the function's name. In C++, function overloading is used to reduce memory usage and increase code reuse.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973036790","position":3,"url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973036790","name":"What is runtime polymorphism C++?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Late binding and dynamic polymorphism are other names for runtime polymorphism. The function call is resolved at runtime in runtime polymorphism. In contrast, with compile time or static polymorphism, the compiler determines which function call to bind to the object after deducing it at runtime.<br\/>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973120458","position":4,"url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973120458","name":"What is inheritance in C++?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"By using inheritance, existing classes can be extended and reused without being changed, creating hierarchical links between them. A class can be embedded into an object via inheritance. Let's say you include a class A object of type x in the class specification of type B.<br\/><br\/>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973131016","position":5,"url":"https:\/\/www.mygreatlearning.com\/blog\/function-overloading-in-cpp\/#faq-question-1662973131016","name":"What are the advantages of function overloading?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The fundamental benefit of function overloading is that it makes code easier to read and reuse.<br\/>Function overloading is used to improve consistency, readability, and memory efficiency.<br\/>The program's execution is accelerated by it.<br\/>Additionally, code upkeep becomes simple.<br\/>Function overloading gives code flexibility.<br\/>The function's versatility avoids the need for many function names to conduct the same set of functions.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg",500,313,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1-300x188.jpg",300,188,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg",500,313,false],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg",500,313,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg",500,313,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg",500,313,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1.jpg",500,313,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/shutterstock_1564856881-1-150x94.jpg",150,94,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"What is Function Overloading in C++?&nbsp;&nbsp;&nbsp; Two or more functions can have the same name but different parameters; such functions are called function overloading in c++. The function overloading in the c++ feature is used to improve the readability of the code. It is used so that the programmer does not have to remember various&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/29771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=29771"}],"version-history":[{"count":48,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/29771\/revisions"}],"predecessor-version":[{"id":114720,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/29771\/revisions\/114720"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/29775"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=29771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=29771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=29771"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=29771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}