简体   繁体   中英

Visual Studio unable to set conditional expression in breakpoint

How do I set a conditional breakpoint in Visual Studio 2019 (Enterprise or Community Edition) that evaluates using an overloaded operator[] ? I attach a minimal non-working example.

#include <memory>

struct Point3D
{
    private:
        int* _Coordinates = (int*)malloc(3 * sizeof(int));

    public:
        int& operator[](int index)
        {
            return _Coordinates[index];
        }
};

int main()
{
    Point3D point;
    point[0] = 3;
    point[1] = 4;
    point[2] = 5;

    auto const coordOne = point[1];
    auto const isFour = point[1] == 4;

    point[1] = 0; // line #25, set conditional breakpoint here

    // Conditional breakpoints in line 25 using 'Conditional Expression' is 'true' with:
    // isFour == true   // works
    // coordOne == 4    // works
    // point[1] == 4    // Error: no operator '[]' matches these operands
}

The VS debugger won't evaluate overloaded operators. You'll have to do that yourself in the debugger expression. So you should set the conditional breakpoint using point._Coordinates[1] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM