I want to do an if like:
if(x has not been initialized)
{...
}
Is this possible? Thanks
"There is no way of checking of the contents of a variable are undefined or not. The best thing you can do is to assign a signal/sentinel value (for example in the constructor) to indicate that further initialization will need to be carried out."
Alexander Gessler
from here
To implement that behavior you may use pointers, default initiated to 0.
For example:
int *number = 0;
// ...
if (!number) {
// do something
}
You may use that trick with any types, not just integers:
Cat *kitty = 0;
// ...
if (!kitty) {
// do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With