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]
.