The name of a function is a pointer to the function...
But in case of function overloading the names of two functions are the same...
So which function does the name point to?
A pointer to a function points to the address of the executable code of the function. You can use pointers to call functions and to pass functions as arguments to other functions.
Originally Answered: What is the difference between pointer to function and function pointer? A function pointer points to the memory address, where the function's code is stored. So unlike other functions function pointer points to code rather than data. e.g.
Functions have same name but different number or different type of parameters. Functions have same name ,same number and same type of parameters. Overloading of the functions take place at compile time. Overriding of the functions take place at run time.
An overloaded function is really just a set of different functions that happen to have the same name. The determination of which function to use for a particular call is resolved at compile time. In Java, function overloading is also known as compile-time polymorphism and static polymorphism.
It depends on the context; otherwise it's ambiguous. See this example (modified except below):
void foo(int a) { }
void foo(int a, char b) { }
int main()
{
void (*functionPointer1)(int);
void (*functionPointer2)(int, char);
functionPointer1 = foo; // gets address of foo(int)
functionPointer2 = foo; // gets address of foo(int, char)
}
You can do this in many ways, but the #1 rule?
Otherwise you'll break type safety and probably shoot yourself in the foot either then or later.
(Issues can come up with calling conventions, random changes you don't notice, etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With