Sign in to follow this  

Case expression not constant?

This topic is 3579 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
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
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

This topic is 3579 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this