Function Overloading
Function Overloading
Contents
• Overloading Constructor Functions
• Exercises
Overloading Constructor Functions
• It is possible and common to overload a class’s constructor function.
However, it is not possible to overload a destructor.
• To support arrays
• It is possible to specify precisely how one object will initialize another by defining a copy
constructor.
• Once defined, the copy constructor is called whenever an object is used to initialize another.
}
Using Default Arguments
• This is a feature of C++ that is related to function overloading.
• This feature is called the default argument, and it allows you to give a
parameter a default value when no corresponding argument is specified
when the function is called.
• Once you begin to define default parameters, you cannot specify any
parameters that have no defaults.
Overloading and Ambiguity
• Overloading-caused ambiguity can be introduced through type conversions,
reference parameters, and default arguments.
• Extend the Person class from exercise 1 with a copy constructor that creates
a new object by copying the attributes of an existing object.