Bool 永远不会为 NULL [-Waddress]
Bool will never be NULL [-Waddress]
我开始使用 C++ 并收到此警告:
../src/loop.cpp:23:6: 警告:'bool almostComparison(double, double)' 的地址永远不会为 NULL [-Waddress]
谁能给我解释一下这是为什么?如果意图只是比较返回真假?
我一直在研究其他问题,但答案太高级了,我无法理解发生了什么。谢谢你帮助我:)
#include <iostream>
using namespace std;
bool almostComparison(double number1, double number2) {
if (number1 + 1 == number2 || number2 + 1 == number1) {
return true;
}
return false;
}
void numberComparison(double number1, double number2) {
if(number1 < number2) {
cout << "the smaller value is: " << number1 << '\n';
cout << "the larger value is: " << number2 << '\n';
if(almostComparison) {
cout << "the numbers are almost equal!" << '\n';
}
} else if (number2 < number1) {
cout << "the smaller value is: " << number2 << '\n';
cout << "the larger value is: " << number1 << '\n';
} else {
cout << "the numbers are equal" << '\n';
cout << "Number1: " << number1 << '\n';
cout << "Number2: " << number2 << '\n';
}
}
int main() {
bool condition = true;
double number1 = 0;
double number2 = 0;
while(condition) {
cin >> number1;
cin >> number2;
if(cin.fail()) {
condition = false;
} else {
numberComparison(number1, number2);
}
}
return 0;
}
if(almostComparison) {
这将测试函数的地址,它始终是 non-NULL。你想像这样实际调用函数:
if(almostComparison(number1, number2)) {
我开始使用 C++ 并收到此警告:
../src/loop.cpp:23:6: 警告:'bool almostComparison(double, double)' 的地址永远不会为 NULL [-Waddress]
谁能给我解释一下这是为什么?如果意图只是比较返回真假?
我一直在研究其他问题,但答案太高级了,我无法理解发生了什么。谢谢你帮助我:)
#include <iostream>
using namespace std;
bool almostComparison(double number1, double number2) {
if (number1 + 1 == number2 || number2 + 1 == number1) {
return true;
}
return false;
}
void numberComparison(double number1, double number2) {
if(number1 < number2) {
cout << "the smaller value is: " << number1 << '\n';
cout << "the larger value is: " << number2 << '\n';
if(almostComparison) {
cout << "the numbers are almost equal!" << '\n';
}
} else if (number2 < number1) {
cout << "the smaller value is: " << number2 << '\n';
cout << "the larger value is: " << number1 << '\n';
} else {
cout << "the numbers are equal" << '\n';
cout << "Number1: " << number1 << '\n';
cout << "Number2: " << number2 << '\n';
}
}
int main() {
bool condition = true;
double number1 = 0;
double number2 = 0;
while(condition) {
cin >> number1;
cin >> number2;
if(cin.fail()) {
condition = false;
} else {
numberComparison(number1, number2);
}
}
return 0;
}
if(almostComparison) {
这将测试函数的地址,它始终是 non-NULL。你想像这样实际调用函数:
if(almostComparison(number1, number2)) {