You are on page 1of 6

Experiment No: 03

Experiment Name: Introduction to Function Overloading, Constructor Overloading, Name


Space Class and Name Space Function with Implement Code.

Objectives:
1. Defining multiple functions with the same name within the same scope, albeit with varying
parameters or parameter types is allowed.
2. Constructor overloading, akin to function overloading, allows for the instantiation of various
constructors within a class, each accepting a distinct parameter set.
3. Organizing code and avoiding naming clashes are facilitated by namespaces. A namespace
class denotes a class confined within a namespace.
4. Resembling a namespace class, a namespace function denotes a function confined within a
namespace.
5. To test the functionality of overloaded constructors and functions by invoking them with
different parameter combinations

Introduction to C++
C++ is a general purpose, case-sensitive, free-form programming language that supports object-
oriented, procedural and generic programming. Also C++ is a middle-level language, as it
encapsulates both high and low level language features.

Function Overloading in C++


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.
Constructor Overloading in C++
A constructor is a special type of method in a class that is called when an object of that class is
created. The main objective of a constructor is to initialize all the data members of a class to
default value (set to zero) when an object of that class is created. A constructor must have the
same name as the class and it does not have a return type, not even void.
Namespace in C++
Namespace in C++ is the declarative part where the scope of identifiers like functions, the name
of types, classes, variables, etc., are declared. The code generally has multiple libraries, and the
namespace helps in avoiding the ambiguity that may occur when two identifiers have the same
name.
Namespace Function
Namespace Class
Conclusion: In conclusion, function overloading, constructor overloading and namespaces play
essential roles in improving code organization and flexibility. Function overloading permits the
declaration of multiple functions with identical names but varying parameter lists, fostering
clarity and adaptability. Constructor overloading, when applied to class constructors, facilitates
the creation of objects with diverse initialization options, thereby enhancing flexibility in object
instantiation. Namespaces offer a structured approach to grouping related elements, such as
functions and variables, thereby averting naming conflicts and fostering modular design.
Collectively, these attributes contribute to creating cleaner, more modular codebases, minimizing
redundancy, and improving the readability and maintainability of code.

You might also like