|"what was the point of setting a prototype?"|
Prototypes are essential in some cases:
1) Consider this example:
int main( )
void X( )
This is an error. Since the compiler reads the file from the top to the bottom, the compiler cannot ensure that the call to "X( )
" is correct until it sees the corresponding prototype. Therefore, the compiler will generate an error.
2) Prototypes allow a program to be divided into multiple files. In the traditional fashion, headers contain the prototypes (interfaces) while the translation unit contains the definitions.
|"Why not just declare the constructor inside the class?"|
You could, but that would implicitly mark the function as "possibly in-line-able
". In-line functions are not always respected by the compiler as functions marked "inline
" serves only as a hint to the compiler that the function should be in-lined if the compiler agrees. Now, while in-lining is a good thing, it's also a bad thing. If all functions are in-lined by the compiler, you risk large performance loses and program size gains.
|"What is the advantage of doing setting out a class as above?"|
None that I can think of. In larger classes, shoving all the definitions of member-functions inside the containing class only reduces readability.