Classes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Classes

when creating a class is it better to create it on a seperate header file and an implementation source code, or have it all on one source code? Any particular reason you would chose one over the other?

8th Dec 2016, 6:21 PM
Beesh B
Beesh B - avatar
3 Answers
+ 2
Splitting your source code is a good practice because if you change something in One file, you dont need to recompile everything, just the changed file. it is also a good practice to keep the Header files simple, that means that the most includes are done in the cpp. Note that you can define multiple cpp for one Header/class (possibility to Split definitions in multiple cpp). but sometimes it is needed to define a class just in the cpp, to keep it private. it is possible to include a cpp file, but this is very bad practice. never do a using Namespace inside a Header!
10th Dec 2016, 3:38 PM
Chris W
Chris W - avatar
0
Yes i think this is good approach to make seperate header file for executing task for smoother execution at run time. Simply your main should not take all the load of code you've made divide task make classes and use them wisely
8th Dec 2016, 6:36 PM
Vipul Walia
Vipul Walia - avatar
0
in header: looks better, easier to understand in source: works faster
1st Mar 2022, 10:20 PM
Radosław Sienkiewicz