Member classes versus #includes
- by ShallowThoughts
I've recently discovered that it is bad form to have #includes in your header files because anyone who uses your code gets all those extra includes they won't necessarily want.
However, for classes that have member variables defined as a type of another class, what's the alternative?
For example, I was doing things the following way for the longest time:
/* Header file for class myGrades */
#include <vector> //bad
#include "classResult.h" //bad
class myGrades
{
vector<classResult> grades;
int average;
int bestScore;
}
(Please excuse the fact that this is a highly artificial example)
So, if I want to get rid of the #include lines, is there any way I can keep the vector or do I have to approach programming my code in an entirely different way?