Overload a method or use default values? c++

后端 未结 4 1288
再見小時候
再見小時候 2021-01-04 01:11

I\'m still relatively new to C++ and I can\'t seem to figure out the difference in the following two ways of coding a function that may take one parameter or maybe two or th

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 01:51

    You are making use of the overloading feature, if you provide several constructors. The advantage in this case is, that you can react differently in every constructor on the passed arguments. If that is of importance use overloading.
    If you can provide decent default values for your parameters and these wouldn't affect the proper running of your code, use default parameters.

    See here for a thread on SO.

提交回复
热议问题