function vs header

For the past couple weeks I've been writing a helpful program that keeps track of all of the electonic parts I have and I keep adding features so the program is getting much larger then anything else I've written. So are there general rules or guidelines on when to add a function or when to add a header file instead? I feel I'm not being very consistent or that maybe I'm adding to many header files.
Thanks in advance.
The general rule of thumb is one header file per class. Adding a function should be done when you need new functionality or if you find that an existing function can be split into several self-contained tasks - in that case you should add additional functions that perform these smaller tasks.
"function" and "header" are orthogonal terms. There is no "function" vs "header".

What is it you really want to know? Are you asking about "free function vs member function"? Or "header vs source file"?
For instance, my Main function reads in text files to store values in arrays and prints out a menu of options. One of these options outputs a table of electronic parts (like resistors, capacitors, etc.) and how many of them I currently have in stock. It gets the values from the text files it initially read in.
When I choose this option from the main menu, should it be a seperate function in the .cpp file or should it be in a .h file?
That is what I am trying to ask.
There's no right answer for that question. It depends entirely on how you want your code organized.

If the new function fits the theme of the functions you have in that cpp file, then it makes sense to put the new function in that cpp file.
Topic archived. No new replies allowed.