what's an overloaded function ? why ar they useful ?
thnx
what's an overloaded function ? why ar they useful ?
thnx
An overloaded function is a function with the same name that performs different operations on different data. So instead of having
void calcFloat(float x, float y, float z);
void calcInt(int x, int y, int z);
void calcTwoInt(int x, int y);
you could use
void calcNum(float x, float y, float z);
void calcNum(int x, int y, int z);
void calcNum(int x, int y);
Instead of using several function names and confusing yourself you can use a single function name with different parameters according to how you want the data handled. Think of printf, that's a version of overloaded function because it can take different types and numbers of arguments and handle them accordingly. Though overloaded functions are a bit harder to implement in C than C++.
how do u create an overloaded function ? DOesn't there have to be a fixed number of parameters ? How does the function check it ?
> how do u create an overloaded function
You use C++.
C can't do overloaded functions.
-Govtcheez
[email protected]
C can do overloaded functions, but you have to get into variable lenth argument lists and have a lot of conditional programming inside of one function. In C++ you have several functions with the same name, but in C you have one function that can do calculations on all kinds of data. Usually it's not worth it in C.