PDA

View Full Version : c++ question what does this mean?



incus
11-26-2002, 06:04 PM
z=z<0?0:z
i know that this isnt an openGL question but it is in some opengl code that i am trying to incoorperate into my program. i know that it is an if else statement but am unsure of how to read it.
incus

rts
11-26-2002, 06:10 PM
z = z < 0 ? 0 : z

is exactly equivalent to

if (z < 0)
{
z = 0
}
else
{
z = z;
}

incus
11-26-2002, 06:15 PM
thanks

nexusone
11-27-2002, 05:41 AM
That one problem I have with C++ or OPP, to cryptic, sort of like short hand C.
Also makes the programs hard to follow.

http://www.opengl.org/discussion_boards/ubb/smile.gif



Originally posted by rts:
z = z < 0 ? 0 : z

is exactly equivalent to

if (z < 0)
{
z = 0
}
else
{
z = z;
}

Deiussum
11-27-2002, 08:22 AM
Huh? The ?: notation is a C thing, not C++. Has nothing at all to do with OOP. It's basically just a short-hand notation for if/then/else. http://www.opengl.org/discussion_boards/ubb/smile.gif