Hi,
The thread on 'Begginer's question, Function overloading' made me wonder about
the following:
Following Brian's example (I'm not criticizing his code), reproduced partially
below, it's clear how overloading works. But it seems to me it could be
a very dangerous feature of the C++ language. If you meant to call
function with 2 parameters 1.1 and 2.2 but wrote a comma instead you wouldn't
get a error message, you would get a totally different function.
I would imagine the 2 functions would be similar or else they would have
different names right? So it might be very difficult to detect that the
wrong function has been called in a large program.
When a support programmer changes the 2,2 to 2,3 really bad things might happen.
Overloading seems very risky in critical applications with rare corner cases.
It's the opposite of the graceful failure I would want in an airplane control
system for example. After all, you never test every possibility.
Comments?
Rob.
--------------------------------------------------------------
From: Brian Pribis <br...@su...>
Notice that both these functions are called 'function'. You must give
them the SAME name but different parameters. The compiler will know
which function to call depending on the parameters. If I call:
function(32,3.0);
the compiler will use the first function. However, if I call:
function(32.1,33.4.92.923);
the compiler will automatically call the second function. Isn't it
wonderfull?!
|