• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Unsafe use of type 'bool' in operation (TFS 1.3)

peteralto

Member
Joined
Nov 1, 2020
Messages
93
Solutions
1
Reaction score
17
I'm getting some warnings during the compilation, one of them is described in the title, but the information follows:

C++:
1>C:\src\game.cpp(4642,29): warning C4804: '>': unsafe use of type 'bool' in operation
1>C:\src\game.cpp(5084,184): warning C4100: 'ipBanishment': unreferenced formal parameter
1>C:\src\game.cpp(5084,166): warning C4100: 'statementId': unreferenced formal parameter
1>C:\src\game.cpp(5084,105): warning C4100: 'action': unreferenced formal parameter
1>C:\src\game.cpp(5084,79): warning C4100: 'reason': unreferenced formal parameter
1>C:\src\game.cpp(5084,43): warning C4100: 'playerId': unreferenced formal parameter


The first warning would be on this line:
C++:
    if (!player->getAccountType() > ACCOUNT_TYPE_NORMAL)
        return false;

The others to that:

C++:
bool Game::playerViolationWindow(uint32_t playerId, std::string name, uint8_t reason, ViolationAction_t action, std::string comment, std::string statement, uint32_t statementId, bool ipBanishment)
{
    return true;
}

Someone with knowledge of C++ would be able to tell what is wrong, if there is something that can be replaced in this case I would appreciate the help.

Thanks.
 
Solution
You are trying to define two things in one bool, that usually wont return any good. I'm not sure of what you are trying to accomplish in that code snippet since you didn't post the entire function.

However try this: (returns false if player has less credentials than tutor)
C++:
    if (player->getAccountType() < ACCOUNT_TYPE_TUTOR)
        return false;
You are trying to define two things in one bool, that usually wont return any good. I'm not sure of what you are trying to accomplish in that code snippet since you didn't post the entire function.

However try this: (returns false if player has less credentials than tutor)
C++:
    if (player->getAccountType() < ACCOUNT_TYPE_TUTOR)
        return false;
 
Last edited:
Solution
You are trying to define two things in one bool, that usually wont return any good. I'm not sure of what you are trying to accomplish in that code snippet since you didn't post the entire function.

However try this: (returns false if player has less credentials than tutor)
C++:
    if (player->getAccountType() < ACCOUNT_TYPE_TUTOR)
        return false;
With this change the warning disappeared. Thank you very much.

About these other warnings from this other line, would you have any suggestions?
C++:
1>C:\src\game.cpp(5084,184): warning C4100: 'ipBanishment': unreferenced formal parameter
1>C:\src\game.cpp(5084,166): warning C4100: 'statementId': unreferenced formal parameter
1>C:\src\game.cpp(5084,105): warning C4100: 'action': unreferenced formal parameter
1>C:\src\game.cpp(5084,79): warning C4100: 'reason': unreferenced formal parameter
1>C:\src\game.cpp(5084,43): warning C4100: 'playerId': unreferenced formal parameter


C++:
bool Game::playerViolationWindow(uint32_t playerId, std::string name, uint8_t reason, ViolationAction_t action, std::string comment, std::string statement, uint32_t statementId, bool ipBanishment)
{
    return true;
}
 
"unreferenced formal parameter"
means you have argument defined but not used.
Look at your arguments in playerViolationWindow
none of these args are used in scope of the method.
Remove their names to get rid of the warning for example uin32_t playerId, to uin32_t,
 
Back
Top