This is going to sound stupid but... I forgot how to use .h files in basic c++ programs.
I know how to declare the .h file and use the functions, but I forgot how to make the function in the .h file.
Like what is the basic code for it?
Printable View
This is going to sound stupid but... I forgot how to use .h files in basic c++ programs.
I know how to declare the .h file and use the functions, but I forgot how to make the function in the .h file.
Like what is the basic code for it?
main.cpp ->
main.h ->Code:#include "main.h"
int main()
{
Hello();
return 0;
}
Code:#include <iostream>
void Hello()
{
std::cout << "Hello World";
}
ahh yes void. Alright thanks a ton!
NO NO NO NO NO NO NO NO!
Headers should not contain non-template implentation.
Your headers should contain prototypes, type declartions, global consts, things like that.
foo.h
foo.cppCode:#ifndef FOO_H_
#define FOO_H_
// Header guards to prevent multiple includes in the same complation unit
struct FOO
{
int x;
};
const unsigned int MAX_LENGTH = 20;
// The following function does foo
void foo(const FOO&);
#endif
main.cppCode:#include <iostream>
#include "foo.h"
void foo(const FOO& f)
{
std::cout<<f.x<<std::endl;
}
Code:#include <iostream>
#include "foo.h"
int main()
{
FOO f = { 10 };
foo(f);
}