I have a class consisting of variable members and a function member. The variable member occasionally changes. I want the function to be called automatically upon the variable changes. In other words, how can I tie the variables inside a class?
class line
{
double x, y; // The poition of the lind end. The line starts at the origin (0,0)
double l; // The length of the line
void length()
{
l = Math.sqrt(x*x+y*y);
}
}
In example above, I need the length to be updated when x and y change.