I need to ignore an uninitialized variable in C++ when I reach the end of my grid.
pointMapIt++;
float nextPointRow;
if (pointMapIt != grid.points.end())
{
nextPointRow = 3.0;
pointMapIt--;
}
if (point.dr != nextPointRow)
//Do stuff
pointMapIt is an iterator passing through my grid points. It checks against nextPointRow every iteration. The program will crash at the final iteration, because nextPointRow will not have been set.
I cannot set nextPointRow to 0.0, because 0.0 is an actual valid input. In fact, I really have no way of telling what nextPointRow will be. So what I really need is to be able to (initialize nextPointRow to and) check nextPointRow against NULL, like so:
if (nextPointRow != null && point.dr != nextPointRow)
Is there a way I can do this or circumvent the issue altogether?
The easiest might be setting
nextPointRowtoNAN.Alternatively, have a boolean flag alongside
nextPointRowthat would indicate whether the latter contains a valid value.Yet another option is to rearrange your code like so: