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]
.
设置条件断点
如何在 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]
.