I know that this is a silly question, but I am new to c++ and it's development environment and I want to learn it the right way.
I am trying to learn how CMake works. Using CLion (which dynamically generated the CMakeList.txt), I saw that when a class is created, both the .cpp and .h are added to the target executable. But when removing the .h file from the add_executable call, the code compiled just fine, even tho in main.cpp there was a #include reference to that header file.
My question is if adding headers to the target executable is optional or not? I normally use VSCode which doesn't generate the CMakeList.txt for me and I wouldn't want to make a habit of not including headers to the target executable if I am supposed to do so.