Multiple Source files?

Hey guys!

I just figured out that I may missed a important point in C++ or programming itself. Actually I'm already pretty far with basic stuff - I understood classes, objects and pointers etc.

I already managed to create a console application where I can move a X around through W,a,s,d on a quad field.

But now I realised that I missed something with file management.

Since now I only used my main.cpp and two header files (.h).

Now I realised that some coders use header_name.h and header_name.cpp - actually one header file .h where the functions are declared and the source file .cpp where the function file is actually defined. Is this important anyhow?

Because I use my headerfiles .h for declaring (like my classes) and also defining those function members from that class directly in that header file.

Is this any kind of bad coding behaviour?

Or do ppl only use different source files to split the headers function declarations from the definitions to make it more readable - where I have to say I don't see a difference of readability of splitting off the definitions from the declarations. I would like to see my declares and defines in one file that being split into two different ones.


Please put me back in order guys ! ;)
Is this important anyhow?
If your header file contains non-inline non-templated function definition then its inclusion in two or more cpp files will lead to errors.

Is this any kind of bad coding behaviour?
Yes.
Or do ppl only use different source files to split the headers function declarations from the definitions to make it more readable
That is too. Though nothing prevents you to create whole program in one file without using headrs at all, it will be hard to navigate and any chnge will lead to recompilation of whole program. Also it hampers code reuse, and any possibility of further extension.
Well since I didn't had that much of a tutorial for "inline" (going through the tutorial of cplusplus.com) and templated functions (well these were already mentioned but not in combination with headers etc.) I don't think I will really realise the need of splitting it up.

Do you have any ressource I can read to really get comfortable with that?


greets Charlie
Topic archived. No new replies allowed.