i need answer

hello every body, i'm mo3taz from egypt and this is the first message i type here, and i've a question;
is it important to make a prototype for the function and then define the body of it in another part of the program?

if it's why??

i think i can just define all the function's parameters and body in one block;

please forgive me if my english was bad; i wait for answers.
declaration (you said the prototype) increases the code readability at least. readability is realy important in C++. In the project team, there are guys that only need the function decleration to uderstand what a function can do.
Last edited on
well what leo said is perfectly right...
still to answer your question, see if you use a function before it is declared, cpp will crib about it....
However if you give a prototype for a function without its body and then declare the body later, compiler won't trouble you...
Thats because it knows that there is sth in the world corresponding to your function name (however it doesn't have a defn by now, however compiler doesn't care for the defn at this time!) when it first encounters the statement where it is used and then the body block actually links to the original prototype which you declared earlier....
So mostly prototypes are used mostly when the defn is to be given after the execution part has been given....
Also not that, when working with a class, it is much more advantageous to (as mentioned above), to make all the declarations in a .h file and the code in some other file... It automatically takes half the care of documentation!!
regards,
Pratyush
thank you so much
that was useful
Topic archived. No new replies allowed.