• Advertisement
Sign in to follow this  

Converting Booleans

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

Hey, I'm using pointers for booleans right now and I don't get this Example 1
    bool* pBool;
    bool bBool = false;
    pBool = &bBool;
    //pBool is still true

Example 2
    bool pBool;
    bool bBool = false;
    pBool = bBool;
    //pBool is still true...

Is there any way of assigning a boolean to another boolean?

Share this post


Link to post
Share on other sites
Advertisement
I dont see you dereferencing the pointer...

Try this:

bool* pBool;
bool bBool = false;
pBool = &bBool;

std::cout << *pBool;

It should display 0(false)

Your second example should work. How are you determining if it is false or true? false is 0, true is any non-zero value.

Share this post


Link to post
Share on other sites
If you're doing:
if (pBool) ....
then yes, it will always be true, unless you assign NULL to it.

Because you're not testing the boolean, but pointer. That would be the basic non-NULL pointer test.

To get value of pointed-to object, do:if (*pBool) ...

Share this post


Link to post
Share on other sites
0 is false? Oh in that case it worked. I assumed that since "return 0" was the same as returning true, 0 was true. Sorry about that

And thanks Antheus for helping me with the if(pBool) thing :)

Share this post


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

  • Advertisement