Hi, I'm still a beginner to C++ (my older sibling is in college and I use his textbook)
I thought this would be the appropriate topic to ask my question regarding how to implement functions (the style). I admit to watching some videos (which I only use as a supplement because sometimes it makes it easier to watch someone write code), but I'm confused to what is appropriate for laying out functions.
The two videos I was watching here...
http://www.youtube.com/watch?v=3pAWJ40I1QE (functions w/out parameters)
http://www.youtube.com/watch?v=wwNFo95S75A (functions w/ parameters)
... says you have to do what is called declaring functions above your main function with comments like this (sorry if the below looks bad, never used CODE tags before):
1 2 3 4 5
|
int myFunc(int, string);
// myFunc - description of function
// @param int - description of first datatype
// @param string - description of second datatype
// @return int - description of what is being returned
| |
... and to have the body of the function
below the main function like this
1 2 3 4 5
|
int myFunc(int num1, string newString) {
// body of code
}
| |
My brother's textbook doesn't talk about function declarations or comments, only shows us how to define functions
above the main function. What standard should I follow?
Also, in the second video, the guy only put the datatypes of the parameters in the declarations, but placed both the datatypes and the variable names in the definitions. Why is that?