I think this makes sense, so I have created a new, default C++ console, just to get a clear test case for this. I have set up the following three header files:
holdingObject.h has the "object" class you are talking about:
class TriangleObject;
class SquareObject;
class HoldingObject
{
public:
TriangleObject *pTriangle;
SquareObject *pSquare;
};
which forward declares the used pointer types. Then I have the two stored types:
squareObject.h
class SquareObject
{
public:
int GetSquareColour() { return 1; }
};
triangleObject.h
class TriangleObject
{
public:
int GetTriangleColour() { return 1; }
};
then I have the main file where I use this deeply complex code
#include "holdingObject.h"
int main()
{
HoldingObject *pObject = new HoldingObject();
pObject->pSquare->GetSquareColour(); // line that breaks compiling
std::cout << "Hello World!\n";
}
as it stands, this code does NOT compile, since I have only included the holding object header file. If I comment out the problem line the code compiles quite happily. If I place the keyboard caret into "pSquare" on this line, Add Include is NOT offered, since the required header file is already included. If I place the caret into "GetSquareColour" then Add Include IS offered, and is offering to add:
#include "squareObject.h"
which seems to be what you are asking for.
I have tested this using VS2022 and VA 2502.0. Have I understood what you are describing correctly? Or have I not followed properly?
It could be my test case is to simple, but if so, what strangeness are you performing?