<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4794,"date":"2022-08-19T08:06:07","date_gmt":"2022-08-19T08:06:07","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4794"},"modified":"2022-08-19T08:06:07","modified_gmt":"2022-08-19T08:06:07","slug":"what-is-overloading","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/","title":{"rendered":"What is Overloading ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">If a single object behaves in many ways, it is known as overloading.<\/li>\n<li style=\"text-align: justify;\">It provides different versions of the same function while a single object has the same name.<\/li>\n<li style=\"text-align: justify;\"><a href=\"https:\/\/www.wikitechy.com\/tutorials\/c++\/\">C++<\/a> facilitates you to specify more than one definition for an operator\u00a0or a function in the same scope.<\/li>\n<li style=\"text-align: justify;\">Overloading consists of two types, they are:\n<ul>\n<li>Operator Overloading<\/li>\n<li>Function Overloading<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"operator-overloading\" style=\"text-align: justify;\">Operator Overloading<\/h2>\n<ul style=\"text-align: justify;\">\n<li>Operator overloading is otherwise known as <strong>compile-time polymorphism<\/strong> in which a standard operator is overloaded to provide a user-defined definition to it.<\/li>\n<li><strong>&#8216;+&#8217; operator<\/strong> is overloaded to perform the addition operation on data types such as\u00a0float, int, etc.<\/li>\n<li>In following functions operator overloading can be implemented such as <strong>Member function, Non-Member function, Friend Function.<\/strong><\/li>\n<\/ul>\n<h3 id=\"sample-code\" style=\"text-align: justify;\">Sample Code<\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-cpp code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-cpp code-embed-code\">using namespace std;    <br\/>class Test    <br\/>{    <br\/>   private:    <br\/>      int num;    <br\/>   public:    <br\/>       Test(): num(8){}    <br\/>       void operator ++()         {     <br\/>          num = num+2;     <br\/>       }    <br\/>       void Print() {     <br\/>           cout&lt;&lt;&quot;The Count is: &quot;&lt;&lt;num;     <br\/>       }    <br\/>};    <br\/>int main()    <br\/>{    <br\/>    Test tt;    <br\/>    ++tt;  \/\/ calling of a function &quot;void operator ++()&quot;    <br\/>    tt.Print();    <br\/>    return 0;    <br\/>}  <\/code><\/pre> <\/div>\n<h3 id=\"output\" style=\"text-align: justify;\">Output<\/h3>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4795\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png\" alt=\"\" width=\"1437\" height=\"175\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png 1437w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading-300x37.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading-1024x125.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading-768x94.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading-390x47.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading-820x100.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading-1180x144.png 1180w\" sizes=\"(max-width: 1437px) 100vw, 1437px\" \/><\/p>\n<h2 id=\"function-overloading\" style=\"text-align: justify;\">Function Overloading<\/h2>\n<ul style=\"text-align: justify;\">\n<li>Function overloading is\u00a0a type of compile-time polymorphism which can define a family of functions with the same name.<\/li>\n<li>The function would perform different operations based on the argument list in the function call.<\/li>\n<li>In argument list\u00a0function to be invoked depends on the number of arguments and the type of the arguments.<\/li>\n<\/ul>\n<h3 id=\"sample-code-2\" style=\"text-align: justify;\">Sample Code<\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-cpp code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-cpp code-embed-code\">using namespace std;    <br\/>class Cal {    <br\/>    public:    <br\/>static int add(int a,int b){      <br\/>        return a + b;      <br\/>    }      <br\/>static int add(int a, int b, int c)      <br\/>    {      <br\/>        return a + b + c;      <br\/>    }      <br\/>};     <br\/>int main(void) {    <br\/>    Cal C;                                                    \/\/     class object declaration.   <br\/>    cout&lt;&lt;C.add(10, 20)&lt;&lt;endl;      <br\/>    cout&lt;&lt;C.add(12, 20, 23);     <br\/>   return 0;    <br\/>}    <\/code><\/pre> <\/div>\n<h3 id=\"output-2\" style=\"text-align: justify;\">Output<\/h3>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4796\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading.png\" alt=\"\" width=\"1423\" height=\"211\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading.png 1423w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading-300x44.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading-1024x152.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading-768x114.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading-390x58.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading-820x122.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/function-overloading-1180x175.png 1180w\" sizes=\"(max-width: 1423px) 100vw, 1423px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If a single object behaves in many ways, it is known as overloading. It provides different versions of the same function while a single object has the same name. C++ facilitates you to specify more than one definition for an operator\u00a0or a function in the same scope. Overloading consists of two types, they are: Operator [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[2080],"tags":[18409,18410,18407,18405,18406,18411,18408,18412],"class_list":["post-4794","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-c-function-overloading","tag-c-operator-overloading-with-examples","tag-c-overloading","tag-function-overloading","tag-function-overloading-in-c","tag-operator-overloading-in-c","tag-what-is-overloading-in-c","tag-what-is-overloading-in-c-with-example"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Overloading - Function Overloading - C++ Overloading - Wikitechy<\/title>\n<meta name=\"description\" content=\"What is Overloading ? - If a single object behaves in many ways is known as overloading. It provides different versions of the same function while a single object has the same name.\" \/>\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.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Overloading - Function Overloading - C++ Overloading - Wikitechy\" \/>\n<meta property=\"og:description\" content=\"What is Overloading ? - If a single object behaves in many ways is known as overloading. It provides different versions of the same function while a single object has the same name.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-19T08:06:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/\",\"name\":\"What is Overloading - Function Overloading - C++ Overloading - Wikitechy\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png\",\"datePublished\":\"2022-08-19T08:06:07+00:00\",\"dateModified\":\"2022-08-19T08:06:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is Overloading ? - If a single object behaves in many ways is known as overloading. It provides different versions of the same function while a single object has the same name.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png\",\"width\":1437,\"height\":175},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Overloading - Function Overloading - C++ Overloading - Wikitechy","description":"What is Overloading ? - If a single object behaves in many ways is known as overloading. It provides different versions of the same function while a single object has the same name.","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.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/","og_locale":"en_US","og_type":"article","og_title":"What is Overloading - Function Overloading - C++ Overloading - Wikitechy","og_description":"What is Overloading ? - If a single object behaves in many ways is known as overloading. It provides different versions of the same function while a single object has the same name.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/","og_site_name":"Wikitechy","article_published_time":"2022-08-19T08:06:07+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/","name":"What is Overloading - Function Overloading - C++ Overloading - Wikitechy","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png","datePublished":"2022-08-19T08:06:07+00:00","dateModified":"2022-08-19T08:06:07+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is Overloading ? - If a single object behaves in many ways is known as overloading. It provides different versions of the same function while a single object has the same name.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/cpp\/what-is-overloading\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/operator-overloading.png","width":1437,"height":175},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4794"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4794\/revisions"}],"predecessor-version":[{"id":4797,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4794\/revisions\/4797"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}