1
私は、以下の機能を持っている:ベクトル<double>の機能にNULLを返すことはできますか?
/* 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;
}
}
は、私がこれを行うと、交差点が存在するかどうNULL
に対してチェックすることができ:
vector<double> v = intersection(pos, dir);
if(v == NULL)
/* Do something */
else
/* Do something else */
これが/悪いコーディングの練習を許可されていない場合は、別の方法で私は何でありますこれについて行くかもしれない?
ベクトルはNULLにすることはできませんが、空にすることはできます()。 –
この質問が表示される場合があります。https://stackoverflow.com/q/29460651/10077 –
通常、NULLはポインタとともに使用されます。しかし、空のベクトルを返し、それが空であれば反対側を検証することができます。 – Rosme