Jump to content
  • Advertisement
Sign in to follow this  
TheMan22

Case expression not constant?

This topic is 3796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get errors case expression not constant, for this part of the code : switch(sAxis.asChar()) { case "X" : MGlobal::displayInfo("x"); break; case "Y" : MGlobal::displayInfo("y"); break; case "Z" : MGlobal::displayInfo("z"); break; } sAxis is a MString variable - maya's api string class This is maya api code,but a c++ programming issue so i am sure you guys can help. By the way MGlobal::displayInfo("x"); just means to print x in maya. thanks

Share this post


Link to post
Share on other sites
Advertisement
single quotes instead of doubles.

switch(sAxis.asChar())
{
case 'X' :
MGlobal::displayInfo("x");
break;
case 'Y' :
MGlobal::displayInfo("y");
break;
case 'Z' :
MGlobal::displayInfo("z");
break;
}

Share this post


Link to post
Share on other sites
Oh yes,i forgot single quotes for char.

so now there is one error left :

error C2450: switch expression of type 'const char *' is illegal

How to solve this?

Share this post


Link to post
Share on other sites
Quote:
sAxis.asChar()


What does this return? char or const char *?

One is a single character, the other is a string.

Share this post


Link to post
Share on other sites
OK, then the error message tells you what's wrong: "switch expression of type 'const char *' is illegal".

You'll have to come up with a different solution, avoiding a switch according to the returned string. Maybe use a chain of if/else if/else or a data structure such as a map. Alternatively, if the returned string is always "X", "Y" or "Z", you could try a switch according to its first character.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!