PDA

View Full Version : [c++] Function Prototyping



kreggz
March 9th, 2009, 10:00 AM
Hello,

I am trying to teach myself c++ and I am wondering what the point of function prototyping is? Seems like you can put your functions above main and avoid compilation problems.

cheers

tneva82
March 9th, 2009, 10:22 AM
Hello,

I am trying to teach myself c++ and I am wondering what the point of function prototyping is? Seems like you can put your functions above main and avoid compilation problems.

cheers

That only works if you need function in the file that contains main.

However the larger the program the more it becomes unfeasible to contain every code in one .cpp file.

Then you need prototypes ;-)

regala
March 9th, 2009, 11:18 AM
Hello,

I am trying to teach myself c++ and I am wondering what the point of function prototyping is? Seems like you can put your functions above main and avoid compilation problems.

cheers

How do you teach yourself c++ ? and which languages do you already know ?

jimi_hendrix
March 9th, 2009, 12:44 PM
if you have a large program and multple .cpp files, you put your prototypes in headers, this lets you use the fuctions elsewhere but lets the compiler knows they exist, but the compiler hasnt found them yet and wont until you link at the end of the build process

abhilashm86
March 9th, 2009, 12:47 PM
function prototyping also tells the type of data type parameters passing to function by calling function,
we help syntax analyzer of compiler inorder to recognise eroors if we pass exeeding parameters or mismatch datatypes.

kreggz
March 10th, 2009, 12:42 AM
Thanks, great replies!

I am using a really old c++ book to teach myself, I know how to do basic vb and bash. This is just as a hobby though.