Simply put, are these two for
cycles functioning the same way:
for (int i = 0; i < (p_size < size ? p_size : size); i++);
for (int i = 0; i < {p_size < size ? p_size : size}; i++);
?
The loop is inside a method (member function), p_size
is its parameter and size
is an attribute (member variable). Microsoft Visual Studio 2015 compiles both codes, but p_size
is not coloured like the other parameters (in the editor) in the code with the curly brackets.
This is valid code:
for (int i = 0; i < (p_size < size ? p_size : size); i++);
This is invalid code:
for (int i = 0; i < {p_size < size ? p_size : size}; i++);
Having curly braces in the middle of the expression like that is invalid.
I'd also in general recommend std::min
:
for (int i = 0; i < std::min(p_size, size); i++);
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