What is the point of making a header file yourself and what do you put in them? I checked the book that I am learning from (as always) and it doesn't say anything 'bout it.
Thanks
-Chris
What is the point of making a header file yourself and what do you put in them? I checked the book that I am learning from (as always) and it doesn't say anything 'bout it.
Thanks
-Chris
You put functions in them and stuff. like this:
Example.h:
And in main.cpp:Code:#include <iostream.h> int function(){ cout << "hi" << endl; return (0); }
it would print:Code:#include "Example.h" int main(){ function(); return (0); }
'hi'
o ya that was me helpin u all me see
Actually, you don't even need to do that much.
//function.hh
void func();
//function.cc
#include <iostream>
using std::endl;
using std::cout;
void func()
{
cout<<"hi"<<endl;
}
//main.cc
#include function.hh
int main()
{
func();
}
would output "hi"
All generalizations are false
There are two reasons why you may want your own header files.
1) You're writing a huge program and want to break it up into manageable pieces.
2) You use the same user-defined functions/classes in a lot of different programs and don't want to have to copy and paste the code every time.
Usually the .h file contains only class definitions and function prototypes (the rest goes in a separate .c* file without a main() function) , but it can contain implementations as well.