Author |
Topic |
|
TomJons
Senior Member
25 Posts |
Posted - Aug 06 2018 : 02:54:54 AM
|
Hey,
I tried to add forward declaration with reference and with pointer, for both I had this option disabled.
i.e.
void fun(T&, T*) {...}
What conditions I must meet to use this VA functionality? I read the documentation and it works for pointers.. :)
Im looking forward for your response :)
Kind regards, Tom |
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Aug 06 2018 : 1:15:14 PM
|
It turns out that add forward declaration is not currently designed to add a forward declaration for a function call, only for actual types. Adding a forward declaration for a function seems a reasonable extension, so I have put in a feature request for this:
case=118238 |
zen is the art of being at one with the two'ness |
|
|
TomJons
Senior Member
25 Posts |
Posted - Aug 06 2018 : 3:48:13 PM
|
Sorry, you misunderstand me...
In given example I would like to add forward declaration of type T, NOT function fun, see below:
void fun(T&, T*) {...}
Expected result:
class T; |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Aug 07 2018 : 06:23:13 AM
|
Is VA offering "Add Include" for the type T in this situation? If VA does not know that this is a valid type then it won't offer to add a forward declaration either. |
zen is the art of being at one with the two'ness |
|
|
TomJons
Senior Member
25 Posts |
Posted - Aug 08 2018 : 09:37:20 AM
|
Yes Add Include working well |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Aug 08 2018 : 10:41:59 AM
|
This is on the function implementation? I just want to check I understand correctly.
If so, then adding a forward declaration for type T won't help you, since the compiler needs the actual definition of type T, since you are now using type T inside the function body. |
zen is the art of being at one with the two'ness |
|
|
TomJons
Senior Member
25 Posts |
Posted - Aug 09 2018 : 05:34:30 AM
|
I created new project and followed guide from your page: https://docs.wholetomato.com/default.asp?W823
my code is:
main.cpp: class A { public: GEdit* ptr_;
};
Header.h: #pragma once class GEdit {};
----- Then I move cursor to GEdit class in main.cpp and still have Add Forward Declaration disabled. Note that Add Include is enabled. What's wrong?
Another example: I added new header Header1.h
class B { public: GEdit* ptr; };
And then Add Forward Declaration works. Is it the only case when it works?
Kind regards Tom |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Aug 09 2018 : 10:43:51 AM
|
I am seeing the same pattern and behaviour here. Thinking about it, there is a logic to this. If we assume you are placing function implementations into the cpp files, but only class / function declarations into header files, then adding a forward declaration into a cpp file does not make much sense, since you will simply end up with code that does not compile, since the forward declared symbol is not declared.
In contrast, in a header file, a forward declaration makes sense, and helps to minimize the number of #include lines added to your header files.
I know that inline functions in your header file break this pattern, but as we have seen VA is not offering to add a forward declaration to a function implementation.
Does this make sense and explain what is going on here? |
zen is the art of being at one with the two'ness |
|
|
TomJons
Senior Member
25 Posts |
Posted - Aug 10 2018 : 04:11:41 AM
|
Yes thank you
Kind regards, Tom |
|
|
TomJons
Senior Member
25 Posts |
Posted - Aug 10 2018 : 07:03:18 AM
|
Ok, one more example: header file: class A { public: A(const Config& cfg) : config_(cfg) {}
private: const Config& config_; };
Add Forward declaration is: - disabled from A constructor arg list (type name, member name) - disabled from A constructor initializer list (type name, member name) - enabled on member list - click at Config (type name) - disabled on member list - click at config_ (member name)
Comparing to - Add Include - it does not matter if I click on type name, member name, where the cursor is.
Consider extending Add Forward Declaration functionality to above examples. :)
Kind regards, Tom |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Aug 11 2018 : 07:38:09 AM
|
This makes sense, I have put in a bug report for this:
case=118345 |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|