How is a function overloaded? Point out the difference between overloading and overriding explain with example.

Answer: – C++ allows specification of more than one function of the same name in the same scope. These are overloaded function and are described in detail in overloading. Overloaded functions enable programmers to supply different semantics for a function, depending on the types and number of arguments.

For example, a print function that takes a string (or char *) argument performs very different tasks than one that takes an argument of type double. Overloading permits uniform naming and prevents programmers from having to invent names such as print_sz or print_d. The following table shows what parts of a function declaration C++ uses to differentiate between groups of functions with the same name in the same scope.

Overloading considerations –

Function declaration element

Used for overloading?

Function return type No
Number of arguments Yes
Type of arguments Yes
Presence or absence of ellipsis Yes
Use of typedef names No
Unspecified array bounds No
Const or volatile (see below) Yes


Although function can be distinguished on the basis of return type, they cannot be overloaded on this basic. Const or volatile are only used as a basis for overloading if they are used in a class to apply to this pointer for the class, not the function’s return type. In other words, overloading applies only if the const or volatile keyword follow the function’s argument list in the declaration.



Having same method name with different signatures. Methods name and signatures must be same.
Overloading is the concept of compile time polymorphism. Overriding is the concept of runtime polymorphism.
Two function having same name and return type, but with different type and / or number of arguments is called as overloading. When a function of base class is re-defined in the derived class called as overriding.
It does not need inheritance. It needs inheritance.
Method can have different data type. Method should have same data type.
Method can be different access specifies. Method should be public.

Comments are closed.

Create a website or blog at

Up ↑

%d bloggers like this: