Function Prototypes

I l @ ve RuBoard

Function Prototypes

In C++, function prototyping is mandatory, but it is optional in C. This difference shows up if you leave the parentheses empty when declaring a function. In C, empty parentheses mean you are foregoing prototyping, but in C++ they mean the function has no prototypes. That is, in C++, the prototype

 int slice(); 

means the same as the following:

 int slice(void); 

For example, the following sequence is acceptable, if old-fashioned, C but an error in C++:

 int slice(); int main() { ...    slice(20, 50); ... } int slice(int a, int b) { ... } 

In C, the compiler assumes you used the older form for declaring functions. In C++, the compiler assumes that slice() is the same as slice(void) and that you failed to declare the slice(int, int) function.

Also, C++ allows you to declare more than one function of the same name , providing they have different argument lists.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net