expression in struct possible?

Started by
5 comments, last by cozzie 11 years, 1 month ago

Hi,

I'm trying to make a switch including expressions, but the compiler unfortunately doesn't 'eat it'.

The code/ thing I'm trying:


switch (pNrPointLights)
{
	case <=4: // do stuff
	case >4 && <=8: // do other stuff
}

Is this possible in C++ switches?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

Nope. Try 'if' statements.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

switch's only choose a value, the can't evaluate expressions for cases.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

thanks for the quick answers, will go for if statements in this case.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

switch's only choose a value, the can't evaluate expressions for cases.

Yes, although simple arithmetic expressions that can be evaluated at compile time may be supported.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Hi geometrian,

Can you explain a bit more on what you mean?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

That means expressions with only literals or enumeration values that result in a single integer value, such as case FOO + 1:.

The expression in switch can be (almost) whatever you want, but anything after case needs to be a single constant integer (or something that trivially results in that). So, no comparisons, no boolean logic, no function calls, etc. -- integers, like 5 or 8, or 7123, or 213+5.
Thanks, i understand now

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement