[cs13001] Function Overloading

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Oct 23 22:55:45 EDT 2013


> Dear Dr. Nesterenko:
> 
> Could you please offer me a example for function overloading?
> 

Function overloading is the ability, provided by C++, to define
several functions, in particular several member functions, with the
same name that differ by number and type of parameters and return
values. Then, depending on the invocation, the compiler would be able
to select the correct function to invoke.

We studied constructor overloading. Below is an example.

class example{
public:
    // these two constructors are overloaded
    example(void){data=0;}; // inline definition of a void constructor
    example(int d){data=d;}; // inline definition of a regular (non-void)
                             // constructor
private:
    int data;
};

int main(void){
    example e1; // a default constructor is invoked on this object
                // the state of this object will be zero
  
    example e2(55); // regular constructor is invoked on this object
                    // its state will be 55
}


Thanks,
--
Mikhail


More information about the cs13001 mailing list