Consequently:
|
#include <stdio.h>
/* -------------------------------
Definition of function f
------------------------------- */
int f( int x) // definition 1
{
return(x * x );
}
/* ------------------------------------------
Duplicate definition of function f !!!
------------------------------------------ */
float f( float x) // definition 2
{
return(x * x );
}
int main(int argc, char *argv[] )
{
}
|
will result in compile error:
cs255-1@aruba (4822)> gcc overload1.c
overload1.c:16:7: error: conflicting types for f
float f( float x) // definition 2
^
overload1.c:7:5: note: previous definition of f was here
int f( int x) // definition 1
^
|
How to run the program:
|
public class overload1
{
/* -------------------------------
Definition of function f
------------------------------- */
public static int f( int x) // definition 1
{
return(x * x );
}
/* ------------------------------------------
Overloaded definition of function f !!!
------------------------------------------ */
public static float f( float x) // definition 2
{
return(x * x );
}
public static void main(String[] argv)
{
}
}
|
No errors when you compile this Java program !!!
How to run the program:
|