What is the purpose/common practice of source files(.cc)? Can I just create a base class on the header file with virtual functions and declare the derived classes at the same header file with implementations of the virtual functions that I declared on the base class or Do I need to do that on the header file? Can you share a clear and concise article/source to read more about this, If possible?
Asked
Active
Viewed 31 times
-1
-
headers and source files are independent of classes and inheritance. The header must contain all declarations you want to expose to other source files (translation units), while source files aren't shared - only the result of their compilation - object code for functions, definitions of constants etc - is shared via object files. – einpoklum May 15 '22 at 17:52
-
1Other languages, like Java or C#, don't need header files. They use a different mechanism to share classes and interfaces. C++ now has *modules*, which could replace the current practice of headers and source files, and just have source files. (Time will tell if the new *modules* option gains widespread acceptance.) – Eljay May 15 '22 at 18:13