Jump to content
  • Advertisement
Sign in to follow this  
utilae

Set Boolean Variable to opposite, eg if true, set to false, and vice versa.

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

Hi, I am using C++. I have the following code
   if(m_bSelected==true)//toggle boolean variable
       m_bSelected=false;
   else
       m_bSelected=true;

Is there some simpler way to make a boolean variable such as m_bSelected be set to the opposite of what it is set to (eg if true, then set to false, vice versa).

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
mbSelected = !mbSelected


Share this post


Link to post
Share on other sites
In the case that this *IS* a joke:


m_bSelected = m_bSelected ^^ true;

m_bSelected = m_bSelected ? false : true;

m_bSelected = (bool)((((int)m_bSelected)+1)&1);

Share this post


Link to post
Share on other sites
Quote:
Original post by Sr_Guapo
Edit: wow 3 posts in 8 seconds...


Yeah, somebody finally asked a question we all knew.

Share this post


Link to post
Share on other sites
Quote:
Original post by TANSTAAFL
In the case that this *IS* a joke:

m_bSelected = m_bSelected ^^ true;

Ummm, ^^ is not an operator. Or was that the joke?

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!