Home Segments Index Top Previous Next

361: Mainline

In Segment 167, you learned about function prototypes for member functions; here you learn about function prototypes for ordinary functions. As you learned in Segment 167, a function prototype is like a function definition without parameter names or a body.

By supplying a function prototype, you supply only what the C++ compiler needs to know about a function's parameter types and return type in order to prepare calls to the function. In the function prototype of rabbits, for example, the parameter name and the entire body disappear, leaving only the data-type declarations for the return value and the parameter:

int rabbits (int); 

Because the body of the function is supplied later, a function prototype cannot refer to other functions, be they defined or not yet defined. Other definitions can refer to the function once its function prototype has been seen, however.