Member classes versus #includes
Posted
by
ShallowThoughts
on Stack Overflow
See other posts from Stack Overflow
or by ShallowThoughts
Published on 2011-01-30T01:07:03Z
Indexed on
2011/02/04
7:26 UTC
Read the original article
Hit count: 95
I've recently discovered that it is bad form to have #include
s 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?
© Stack Overflow or respective owner