I'm supposed to put my implementations in one file and my prototypes in a header file. But the way I understand it, a header file full of prototypes would not be very useful. What are these things? Is one of them identical to a definition or a declaration?
A function prototype is a function declaration that declares the types of its arguments. This distinction is historical. In C, it is possible to declare a function without a prototype, but in C++ all function declarations are prototypes (so there is no difference in C++).
// In C, this is a declaration but NOT a prototype.
// In C, this function takes an unknown number of parameters.
// In C++, this is a prototype, and the function has no arguments.
void f();
// In C, this is a prototype for a function with no arguments.
// In C++, it is the same thing.
void f(void);
In C++, you can't call functions unless you have a declaration/prototype for the function. That is the use of header files.
(In C, you can call functions without a declaration, but this is considered a bad idea, and you only see it in really old code.)
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