Tuesday, August 11, 2015

C++ Debug when a public double field is being set

C++ Debug when a public double field is being set.

The problem:


  • There is a public field that is a double
  • It gets set a lot
  • You need to know when it gets a certain value
  • Or You need to know when it's value is used or set

The solution:

Replace 'double' with 'DebugableDouble'.
Since it has an equals operator that takes a double, a recompile will use it.
So you don't have to change all of the places it is used to make them use setters and getters.

Here is the class:



class DebugableDouble
{
private:
double m_val;

public:

DebugableDouble(double val)
{
m_val = val;
}

operator double()
{
return m_val;
}

double operator = (double newVal)
{
m_val = newVal;
return m_val;
}
};

No comments:

Post a Comment