Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Add include of underlying type
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sitnduck
Senior Member

47 Posts

Posted - Oct 27 2023 :  07:32:56 AM  Show Profile  Reply with Quote
I have to say I love "add include", I use it all the time. It's probably one of my most often-used shortcuts.

However, something that happens almost nearly equally, is that I am using a pointer object whose type is not defined, e.g.:

pObject->pMyTool->Use();

Often times, pMyTool by itself would be fine, having its type forward-declared in the .h (e.g. class Tool;).

HOWEVER the issue is that the "Tool" class itself needs to be included now that I am using "Use()".

So what I end up doing, and I do this quite often, is to write a throwaway line of code, such as "Tool dummy;", then use visual assist "Add include" on the "Tool" word, so the #include statement is generated at the top of the file, then I erase the throwaway line.

It would be really nice to have a shortcut to "Add include of underlying type", so that it would be able to use its Parsed knowledge of the underlying type of the variable and do that inclusion.

I hope that made sense!:)

feline
Whole Tomato Software

United Kingdom
18958 Posts

Posted - Oct 31 2023 :  08:53:13 AM  Show Profile  Reply with Quote
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?

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000