我有一個相對簡單的算法,走一個std ::向量尋找兩個相鄰的元組。一旦發現X值的左側和右側的元組,我可以在它們之間進行插值。不知怎的,這個工程:爲什麼2個NULL指針不計算爲false?
std::vector<LutTuple*>::iterator tuple_it;
LutTuple* left = NULL;
LutTuple* right = NULL;
bool found = 0;
// Only iterate as long as the points are not found
for(tuple_it = lut.begin(); (tuple_it != lut.end() && !found); tuple_it++) {
// If the tuple is less than r2 we found the first element
if((*tuple_it)->r < r) {
left = *tuple_it;
}
if ((*tuple_it)->r > r) {
right = *tuple_it;
}
if(left && right) {
found = 1;
}
}
,而這一點:
std::vector<LutTuple*>::iterator tuple_it;
LutTuple* left = NULL;
LutTuple* right = NULL;
// Only iterate as long as the points are not found
for(tuple_it = lut.begin(); tuple_it != lut.end() && !left && !right; tuple_it++) {
// If the tuple is less than r2 we found the first element
if((*tuple_it)->r < r) {
left = *tuple_it;
}
if ((*tuple_it)->r > r) {
right = *tuple_it;
}
}
沒有。這是爲什麼?我期望這樣的兩個NULL ptrs在否定時一起評估爲真。
http://en.wikipedia.org/wiki/De_Morgan's_laws – HostileFork 2012-04-10 15:23:15