If I just do this: Ex1:
#include <iostream> int main() { //try to call doSomething function doSomething(); } void doSomething() { std::cout << "Call me now!" << std::endl; }
I get a compilation error! Since the compiler does not know what "doSomething" is.
But if I changed the position of doSomething to come in first place, the program successfully compiles. Ex2:
#include <iostream> void doSomething() { std::cout << "Call me now!" << std::endl; } int main() { //try to call doSomething function doSomething(); }
I can declare a prototype as follows: Ex3:
#include <iostream> void doSomething(void); int main() { //try to call doSomething function doSomething(); } void doSomething() { std::cout << "Call me now!" << std::endl; }
But why does the first example not work? Why do I even need to first declare a prototype or call functions and a main function?
Thank!
c ++ function-prototypes
Ito Nov 20 '11 at 2:45 2011-11-20 02:45
source share