C | C++

[C++] warning C4804: '>': unsafe use of type 'bool' in operation

1984 2022. 1. 30. 22:58
에러
warning C4804: '>': unsafe use of type 'bool' in operation
원인
// 잘못된 문법이다.
if(a < x < b)

// 사실상 아래와 같다.
if((a < x) < b)

// 즉 boolean < b 의 형태이므로 error 발생한다.
if (boolean < b)
해결방법
// 아래와 같이 작성한다. and operator(&&) 사용
if(a < x && x < b)

 

[참고 자료]

https://stackoverflow.com/questions/42552877/why-the-warning-c4804-unsafe-use-of-type-bool-in-operation-is-popping

728x90