vendredi 30 novembre 2018

C++ : Meaning of int n != unsigned int(n)

I was reading a code segment that was checking if some values from a ppm file are correct. The values were read like this:

image >> img_format >> width >> height >> maxval;

And then to check if width and height are correct this was used:

if (width != unsigned int(width) && height != unsigned int(height))
{
    cerr << "Width and/or height of the image are missing." << endl;
    exit(EXIT_FAILURE);
}

**width and height are declared as unsigned int

How does this condition work?

Aucun commentaire:

Enregistrer un commentaire