I include them by default in any class but sometimes I don't use them. |
I'd generally say that this isn't bad for performance, for the reasons outlined above, but it can be bad for compilation times. In general, try not to include anything you don't absolutely have to.
This even extends to your classes - if you have a class
ClassA that's only reference to another class
ClassB is taking it as a parameter, storing an object of that type, or defining it as a friend, you should probably prefer forward-declaring the class rather than including.
This is for two reasons - if you modify ClassB you don't need to recompile other code that uses your code but doesn't know/care about the
ClassB bits. The other is to help to avoid cyclic dependencies - for example
ClassB needs to take a parameter of
ClassA, but
ClassA needs a parameter of
ClassB - you need to forward declare at least one of them, so you may as well do it in general.
TL;DR - Don't include files you don't need.