2 つの異なる許容値をパラメーターとして取る近似関数を作成しています。
bool Approximate(vector<PointC*>* pOutput, LineC input, double horizontalTolerance, double verticalTolerance)
verticalTolerance が設定されていない場合、関数で verticalTolerance = horizontalTolerance を設定する必要があります。だから、私は次のようなことを達成したい:
bool Approximate(vector<PointC*>* pOutput, LineC input, double horizontalTolerance, double verticalTolerance=horizontalTolerance)
ローカル変数はデフォルトのパラメータとして許可されていないため、これが不可能であることはわかっています。私の質問は、この関数を設計する最良の方法は何ですか?
私が考えたオプションは次のとおりです。
デフォルトのパラメーターを使用せず、ユーザーが両方の許容値を明示的に設定するようにします。
verticalTolerance のデフォルト値を負の値に設定し、負の場合は horizontalTolerance にリセットします。
bool Approximate(vector<PointC*>* pOutput, LineC input, double horizontalTolerance, double verticalTolerance=-1) { if (verticalTolerance < 0) { verticalTolerance = horizontalTolerance; } // Rest of function }
私の意見では、ポイント 1 は解決策ではなくバイパスであり、ポイント 2 は最も単純な解決策ではありません。