Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Goto Definition fails on explicit operator bool

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Kram Posted - Oct 08 2021 : 10:56:23 AM
Hello,

Goto Definition works if the cursor is on the operator keyword but not the bool keyword.


namespace test_2
{
    class c
    {
    public:
        operator bool() const {
            return b;
        }

        bool b;
    };

    bool g(const c& p)
    {
        return p.operator bool();
    }
}
3   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Oct 11 2021 : 1:34:22 PM
I didn't know you could call overloaded operators explicitly like this, but it makes sense, seeing it done and running some tests on it here.

I am not entirely sure that this is a bug, since in general using alt-g on the keyword "bool" doesn't make any sense, but since it is part of the operator, and it is the function name, I have put in a bug report for this. But this does illustrate the general point that Alt-g on overloaded operators is a bit tricky.

case=146308
Kram Posted - Oct 08 2021 : 1:13:02 PM
Nothing clever, it's just explicitly calling the operator bool.
I use it mainly during Native Unit Tests as the Assert::IsTrue / IsFalse won't accept a std::shared_ptr without an explicit conversion. This is due to the explicit operator bool declaration. I suppose that I could have just cast it.
feline Posted - Oct 08 2021 : 12:03:28 PM
I am seeing the same thing here. At the risk of asking a silly question, what is "operator bool()" doing? Are you actually overloading casting the class to a bool, or is this doing something else?

Plus, I don't think I have ever seen an overloaded operator called like that before.

Just when you think you are starting to get to grips with C++

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000