I have read that where it is possible it is better to declare a class rather than include it (in a header file).
For example:
Class A;
Class B
{
public:
B();
~B();
A* GetMyVariable();
void SetMyVariable(A* newVal);
private:
A* m_myVariable;
}
Which compiles fine and can be used no problem with the class definitions in their subsequent .cpp files.
However, supposing you now wish to make the get and set functioned inlined (or at least suggest to the compiler that they be) then code would need to change as follows:
//Class A;
#include "A.h"
Class B
{
public:
B();
~B();
inline A* GetMyVariable() { return m_myVariable; }
inline void SetMyVariable(A* newVal) { m_myVariable = newVal; }
private:
A* m_myVariable;
}
So the question is, is one method better than the other and why? Would I be better trying to get as much as possible using class declaration by removing the inline functions from some of my classes or should I keep trying to inline where ever I can?