Code: Select all
conf.fullscreen=conf.fullscreen ? 0 : 1;
Code: Select all
conf.fullscreen=conf.fullscreen ? 0 : 1;
Yes, that's correct also...ATani wrote:Another common construct for this is:
conf.fullscreen = !conf.fullscreen;
Which depending on your compiler will do the same thing..
Mike
Code: Select all
inline void toggle(bool *const boolean) { *boolean = !(*boolean); }
Code: Select all
toggle(&conf.fullscreen);
I passed it as a pointer to follow recommended convention of informing explicitly that the variable is being modified but in this case one could safely assume, I guess.Rand Linden wrote: Also, you can pass the address as a reference, and then avoid the "&" entirely -- put it in the function prototype and forget about it.
Rand.
The const confuses things though, and hence the suggestion to avoid the pointer entirely.nymus wrote:I passed it as a pointer to follow recommended convention of informing explicitly that the variable is being modified but in this case one could safely assume, I guess.
sorry, i tried doing a search but without knowing what the '?' operator was called it was hard to just look for "? C++". Then my second question about more ternary operators was asked because i did a search after finding out what it was called and some places said that it was "a ternary operator" and others said "the ternary operator" and i couldnt find a proper answer. The last question was frivilous i admit, but didnt cause any trouble.Rand Linden wrote:Here's a couple more tips to help you out:
Tip 1: The more frequently you ask questions that could (and SHOULD) have been answered by doing a search, the less frequently people will help you out.
Tip 2: When you post fewer lines of text than your signature, consider not posting at all.
Rand.