answersLogoWhite

0

Function prototypes determine the return type, the name of the function, the argument types expected by the function, and the arity of the function. Function prototyping is used to separate interface from implementation. In C++ all functions must be declared before they are called, thus we use prototypes to provide forward declarations for those functions that have yet to be defined/implemented. We can also use forward declarations for incomplete types such as template functions and classes, however the definition/implementation must be visible to compiler before the function or class is used. In these cases the definitions are typically placed in the same header as the declarations.

It is important to note that a definition is also a declaration, and therefore both are also prototypes. The only real difference is that prototypes do not require names for the formal arguments. Even if you provide argument names in your prototypes, they will be ignored by the compiler. The argument names within the definition are the only names of any relevance.

Function overloading is where two or more functions share the same name within the same namespace, but have different signatures. The signature of a function is essentially the same as its prototype but excludes the return type, thus overloads cannot differ by return type alone. The compiler uses the function signature to differentiate between your overloads.

All function signatures within a namespace must be unambiguous, thus you cannot have two functions with the same name and arguments that are co-variant. For example, the following overloads are invalid because a size_t type is co-variant with unsigned int type, thus the compiler cannot differentiate them.

unsigned int max(unsigned int, unsigned int);

size_t max(size_t, size_t);

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
More answers

function prototype is declaration of function without its body and ends with a semicolon. The return type, parameter type and their order are specified.

Where as

function signature does not give you return type for overloading. This is not the concept in c by the way. Methods in Object oriented languages have method signatures.

Hope this answers your question!

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between function prototyping and function overloading?
Write your answer...
Submit
Still have questions?
magnify glass
imp