The code is terribly complicated. Actually, you want to check if the getAssigment method getAssigment successful and whether the assigned pointer is non-zero.
The Codex verifies that, although confusing, it uses weak typing, rather than trying to encompass explicit and strong typing. As a result, this is not idiomatic C ++, but harder to understand than necessary.
In particular, do not use !!a in C ++. This is an established idiom in weakly typed languages ββsuch as JavaScript to force value to a boolean type. But in C ++ this is usually not used.
It is unclear what the code with hasSolution does is not defined or not used. However, I suspect the code should be equivalent to the following:
Assignment *a; return getAssignment(query, a) and a == nullptr;
(Before C ++ 11, you need to write 0 instead of nullptr .)
However, this code still shows a poor design: why is a passed by reference? Why is this not a return value? Worse, a never used, therefore unnecessary. If a really is not needed, it should be completely eliminated. If necessary, this should be a return value. In other words, the getAssignment prototype should be as follows:
Assignment* getAssignment(the_type_of_query query);
And it should be used simply as follows:
Assignment* a = getAssignment(query);
Also, I suspect that this code actually assigns memory ownership to raw pointer a . This is very discouraged in modern C ++. Either use pointers or a smart pointer.
Konrad Rudolph
source share