Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


expression in struct possible?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 cozzie   Members   -  Reputation: 1757

Like
0Likes
Like

Posted 28 February 2013 - 03:21 PM

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?



Sponsor:

#2 Promit   Moderators   -  Reputation: 7559

Like
0Likes
Like

Posted 28 February 2013 - 03:24 PM

Nope. Try 'if' statements.


Edited by Promit, 28 February 2013 - 03:26 PM.


#3 slicer4ever   Crossbones+   -  Reputation: 3978

Like
0Likes
Like

Posted 28 February 2013 - 03:28 PM

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


Edited by slicer4ever, 28 February 2013 - 03:29 PM.

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

#4 cozzie   Members   -  Reputation: 1757

Like
0Likes
Like

Posted 28 February 2013 - 03:44 PM

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



#5 Geometrian   Crossbones+   -  Reputation: 1598

Like
0Likes
Like

Posted 28 February 2013 - 05:23 PM

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.


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.

#6 cozzie   Members   -  Reputation: 1757

Like
0Likes
Like

Posted 01 March 2013 - 12:10 PM

Hi geometrian,

Can you explain a bit more on what you mean?



#7 samoth   Crossbones+   -  Reputation: 5031

Like
0Likes
Like

Posted 01 March 2013 - 12:27 PM

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.

#8 cozzie   Members   -  Reputation: 1757

Like
0Likes
Like

Posted 01 March 2013 - 04:40 PM

Thanks, i understand now




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS