It is very clear to me when I can / cannot use the forward declaration, but I'm still not sure about one thing.
Let's say I know that sooner or later I have to include a header to remove a reference to an object of class A. I don’t understand if it’s more efficient to do something ...
class A;
class B
{
A* a;
void DoSomethingWithA();
};
and then in cpp there is something like ..
#include "A.hpp"
void B::DoSomethingWithA()
{
a->FunctionOfA();
}
Or could I just include the header header in header file B first? If the former were more efficient, I would appreciate it if someone had clearly explained why, since I suspect that this has something to do with the compilation process, which I could always find out by learning more.
source
share