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
 Technical Support
 Goto Definition fails on explicit operator bool
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kram
Junior Member

Germany
16 Posts

Posted - Oct 08 2021 :  10:56:23 AM  Show Profile  Reply with Quote
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();
    }
}

B00ting, please wait...

Edited by - Kram on Oct 08 2021 10:57:10 AM

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Oct 08 2021 :  12:03:28 PM  Show Profile  Reply with Quote
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++

zen is the art of being at one with the two'ness
Go to Top of Page

Kram
Junior Member

Germany
16 Posts

Posted - Oct 08 2021 :  1:13:02 PM  Show Profile  Reply with Quote
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.

B00ting, please wait...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18749 Posts

Posted - Oct 11 2021 :  1:34:22 PM  Show Profile  Reply with Quote
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

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