Skip to main content

C++ Overloading

C++ Overloading

C++ language allows programmers to specify more than one definition for a function name or an operator. This is one of the many exciting features that Object Oriented Language offers programmers. It is one of the important techniques that has extended the power and flexibility of C++. In this chapter you will learn about the types of overloading and how they are used within a C++ program.

What is Overloading?

Overloading is the technique to use a single identifier to define various methods or techniques of a class that differ in their input and output parameters. The concept of overloading is generally used when a program block conceptually execute the same task but with a slight distinctness in set of parameters.
Overloading is a concept used to avoid redundant code where the same method name or operator is used multiple times but with a different set of parameters or number of operands. The actual method that gets called during runtime is resolved at compile time, thus avoiding runtime errors. Overloading provides code clarity; reduce complexity, and increases runtime presentation of a code.
There are two types of overloading provided by C++. These are:
  • Operator Overloading
  • Function Overloading

Comments

For Programs Click Here

Popular posts from this blog

Syllabus

Syllabus  C Programming Tutorials C Tutorial C Introduction History of C Programming Language C Installation C Program Structure C Input and Output (I/O) C Format Specifiers Declaration & Assignments C Tokens C Identifiers C Keywords C Constants C Operators C Data Types C Variables C Preprocessors C Type Casting C Custom Header File Flow Control C Decision Making C if Statements C if-else Statements C Nested if-else Statements C else-if Statements C goto Statement C switch Statements C Loops C while loops C do while loops C for loops Functions C Functions C Function Arguments C Library Functions C Variable Scope Arrays & Strings C Arrays C Strings Pointers C Pointers C Dynamic Memory Allocation Structure & Union C Structures C Unions File I/O C File Handling C fopen C fclose C getc C putc C getw C putw C fprintf C fscanf C fgets C fputs C feof                                     ...

C++ Constructors and Destructors

C++ Constructors and Destructors Providing the initial value as described in the earlier chapters of C++ does not conform to the philosophy of C++. So C++ provides a special member function called the constructor which enables an object to initialize itself at the time of its creation. This is known as automatic initialization of objects. This concept of C++ also provides another member function called destructor which is used to destroy the objects when they are no longer required. In this chapter, you will learn about how constructors and destructors work, types of constructors and how they can be implemented within C++ program. What are constructors? The process of creating and deleting objects in C++ is vital task. Each time an instance of a class is created the constructor method is called. Constructors is a special member functions of class and it is used to initialize the objects of its class. It is treated as a special member function because its name is the same as the cla...

C if-else Statements

Flow Control C if-else Statements If else statements in C is also used to control the program flow based on some condition, only the difference is: it’s used to execute some statement code block if expression is evaluated to true, otherwise executes else statement code block. The basic format of if else statement is: Syntax: if ( test_expression ) { //execute your code } else { //execute your code } Figure – Flowchart of if else Statement: Example of a C Program to Demonstrate if else Statement  Example: #include <stdio.h> main () { int a , b ; printf ( "Please enter the value for a:" ); scanf ( "%d" , & amp ; a ); printf ( "\nPlease the value for b:" ); scanf ( "%d" , & amp ; b ); if ( a & gt ; b ) {    printf ( "\n a is greater" ); } else {    printf ( "\n b is greater" ); } } Program Output: Example: #include <stdio.h> main () { int num ; printf ( ...