Separating class code into a header and cpp file answers how to declare and define classes using headers and sources; Why can templates only be implemented in the header file? answers why (when you are going to) declaration and definition of a template-functions are done in the header. My question is specific about a functions-only header; specifically about when and why to use them, instead of how to use them.
I am learning how to use headers and multiple source files. I just created a header which I called "ival.hpp" where I implement some template-functions to validate input: test if they match desired types, ask for input of specific types, ask for [y/n] validation... Just very basic things for my level (only functions, no classes in that header).
This brings the question: What is the convention for using headers? Should the main.cpp
only contain the main()
function while everything else is categorized in headers to simplify readability? Are headers only used to define classes (and their functions) by convention? In future projects would it be reasonable to #include "ival.hpp"
instead of just declaring and defining them in the main.cpp
?