Optional function parameters: Use default arguments (NULL) or overload the function?

前端 未结 12 1562
情书的邮戳
情书的邮戳 2020-12-08 00:44

I have a function that processes a given vector, but may also create such a vector itself if it is not given.

I see two design choices for such a case, where a func

12条回答
  •  醉话见心
    2020-12-08 01:16

    I agree, I would use two functions. Basically, you have two different use cases, so it makes sense to have two different implementations.

    I find that the more C++ code I write, the fewer parameter defaults I have - I wouldn't really shed any tears if the feature was deprecated, though I would have to re-write a shed load of old code!

提交回复
热议问题