我有以下功能:
/* Calculate if there is an intersection with given intial position and
direction */
vector<double> intersection(vector<double> startPos, vector<double> direction)
{
if(there is intersection)
return (intersection coordinates);
else {
return NULL;
}
}
Run Code Online (Sandbox Code Playgroud)
我可以这样做并检查NULL是否存在交叉点:
vector<double> v = intersection(pos, dir);
if(v == NULL)
/* Do something */
else
/* Do something else */
Run Code Online (Sandbox Code Playgroud)
如果这是不允许的/糟糕的编码实践,我可以采取的另一种方法是什么?