int and bool confusion

Hello,
I am struggling facing a strange problem which hasn't been showing up so far.

1) warning C4805: '==' : unsafe mix of type 'int' and type 'bool' in operation
2) error C2556: 'int GameManager::initialise(const std::string &)' : overloaded function differs only by return type from 'bool GameManager::initialise(const std::string &)'

Caused by these code fragments:

1)
static std::string formatBoolean(bool value){
std::string toBeReturned("");
if(value == true){//WARNING POINTS HERE
toBeReturned+="true";
}
else{
toBeReturned+="false";
}
return toBeReturned;
}

2)

cpp file:

bool GameManager::initialise(const std::string& stateName){//ERROR POINTS HERE
InputManager::getInstance().setLogger(mLogger);
PhysicsEngineManager::getInstance().setLogger(mLogger);
RenderingEngineManager::getInstance().setLogger(mLogger);
AudioEngine::getInstance().setLogger(mLogger);
return changeState(statesMap[stateName]);
}

.h file
bool initialise(const std::string& stateName);

May you kindly please tell me what's going on


Answer this question

int and bool confusion

  • SG Dunn

    Look for code that tries to redefine bool eg.

    typedef int bool;
    #define bool int



  • l_d_allan

    Many thanks, that was the reason.

    Cheers.

  • Narayan_jn

    Change your code as following;

    static std::string formatBoolean(bool value){
    std::string toBeReturned("");

    if(value){
    toBeReturned+="true";
    }
    else{
    toBeReturned+="false";
    }
    return toBeReturned;
    }

    Have Fun coding!



  • James R-S

    Many thanks,
    that resolved the first issue.
    May you please give me some advice about the second

    Cheers.

  • int and bool confusion