In the following example, the FileA header is included in FileB header; Some of the classes in FileB.h are forwardly declared inside FileA.h;
in FileA.h
//Forward Declaration.
class classB;
//Main classes.
class ClassA
{
//...
private:
void MemberFunction(ClassB* PtrToClassBObj);
}
In FileB.h
//Includes.
#include FileA.h
//Main classes.
class ClassB
{
//...
public:
int MemberVariable = 0;
}
Then in FileA.cpp
#include FileA.h
//Member functions definitions.
void ClassA::MemberFunction(ClassB* PtrToClassBObj)
{
if(PtrToClassBObj)
PtrToClassBObj->MemberVariable++;
}
Is that enough to make FileA.cpp capable of accessing public members of said classes from FileB.h? or should FileA.cpp itself include FileB.h? And was the forward declaration needed (assuming no use of the class name inside FileA.h, and only used inside FileA.cpp exclusively)? What is the general best practice advice if any?