繁体   English   中英

Visual Studio 无法在断点中设置条件表达式

[英]Visual Studio unable to set conditional expression in breakpoint

如何在 Visual Studio 2019(企业版或社区版)中设置使用重载operator[]进行评估的条件断点? 我附上了一个最小的非工作示例。

#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
}

VS 调试器不会评估重载的运算符。 您必须自己在调试器表达式中执行此操作。 所以你应该使用point._Coordinates[1]设置条件断点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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