I was told by my professor that my function prototypes should be included in my *.h file. But, do I also include the function definitions in that file, or do those go in my *.cpp file? Please help..
Josh Stevanus
[email protected]
Printable View
I was told by my professor that my function prototypes should be included in my *.h file. But, do I also include the function definitions in that file, or do those go in my *.cpp file? Please help..
Josh Stevanus
[email protected]
Function definitions go in the .cpp.
An example of how you potentially could have things set up in a sample project...
File.H
File.CppCode:#ifndef FUNC_H
#define FUNC_H
int func(int);
#endif
Main.CppCode:#include "File.H"
int func(int data)
{
...
}
Thus this sample project has 2 cpp files and 1 header file. You compile the 2 cpp files into object files and its the linkers job to combine those (typically along with some other library code) into a fully functioning executable file.Code:#include "File.H"
int main()
{
int result, val;
...
result = func(val);
}