I've been looking through the FAQ and Googling previous threads on
c.l.c++ but I haven't seen this exact situation addressed. I
initialize variables of type float to a known invalid value (of type
const float), and at a later time I want to see if these variables are
still undefined:
#include <iostream>
int main()
{
const float undefined(-999); // valid only as an initial value
float f1(undefined);
if (f1 == undefined)
{
std::cout << "f1 has not been defined\n";
}
float f2(undefined);
f2 = 5;
if (f2 != undefined)
{
std::cout << "f2 has been defined\n";
}
return 0;
}
Expected output:
f1 has not been defined
f2 has been defined
From what I've read, I think (hope) that floating point comparisons
are okay in this case because I'm using the same type for each
variable in the comparisons and no arithmetic is involved.