【问题标题】:Visual Studio unable to set conditional expression in breakpointVisual Studio 无法在断点中设置条件表达式
【发布时间】:2020-11-22 06:47:15
【问题描述】:

如何在 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
}

【问题讨论】:

    标签: c++ visual-studio debugging operator-overloading conditional-breakpoint


    【解决方案1】:

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

    【讨论】:

    • 用表达式测试:point._Coordinates[1] == 4 并且有效。 1) Microsoft 希望我如何找到这些信息? 2) 你从哪里知道的?
    • @VisorZ 1) 通过咨询the documentation。 2) 多年的经验。
    猜你喜欢
    • 2015-02-08
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2013-10-01
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多