I was just wondering what the differencs between putting includes in the header and putting it in the source file, and when you should use what because it seems that people in general uses both.
Leiken
I was just wondering what the differencs between putting includes in the header and putting it in the source file, and when you should use what because it seems that people in general uses both.
Leiken
when you include a header file, the compiler puts the whole file where you typed #include <header.h>
so
if header.h was
when you do:Code:#include <stdio.h> #include <stdlib.h>
it will beCode:#include "header.h" int main(void) { printf("Hello, world!"); return 0; }
Code:#include <stdio.h> #include <stdlib.h> int main(void) { printf("Hello, world!"); return 0; }
You really don't want to put includes in your header files, the header files are mostly used for declarations so there's no point. If you include the standard headers in your own custom header it just makes the program harder to read and distribute since you don't know what was actually included.
Code:/* ------------- header.h ------------- */ #ifndef _HEADER_H_ #define _HEADER_H_ char *function ( int, double ); int foo ( void ); double bar ( double ); #endif-PreludeCode:/* ---------------- program.cpp ---------------- */ #include <iostream> #include <string> #include "header.h" using namespace std; int main ( void ) . . .
My best code is written with the delete key.