Here goes newbie question number 5, but I don\'t have a teacher.. so.. anyhow here we go:
I\'m wondering if is necessary to have function prototypes at the top of the fi
This works when you have tiny functions. It works less well when they get long. Or when you have more than one file of code. As a matter of style, many teachers demand that even tiny applications be written with the structure that serves large applications well.
This declares but does not define the function say_hi
:
void say_hi();
This both declares and defines the function say_hi
:
void say_hi(){
std::cout << "hi" << std::endl;
}
You can declare a function many times; you can only define it once.
A function must be declared in the file before you can call it. A function must be defined somewhere--in the same file before or after you call it or maybe even in a different file.
So, yes, this is perfectly fine.
You are correct; if you define all your functions above where they are called, you don't need function prototypes. The actual function definition serves the same purpose as a separate declaration.