I have:
// file model.h
#include "instrument.h"
class model
{
// A function which uses instruments and returns double.
double value(Instrument instruments);
}
Now in file instrument.h
// file instrument.h
class Instrument
{
// This function needs to use model.
double value2(model* md);
}
Now in file instrument.h, should I be using #include "model.h"? That kind of seems like a bad design.
How do I design this two object Instrument and model so that they know and can use each other?
Forward declarations:
If your class doesn’t contain data members of the other type, you don’t need the full definition of the type. For example, if you have a member pointer, function return values or, like in your case, parameters.
Also, your intuition is correct. You should keep
includes in header files to a minimum. Headers should be self-contained, but not have unnecessary headers.