0

I'm a Python developer learning C++. In Python there's no way to overload a function or a method - you just provide defaults. But in C++ you can have both, so when would you chose one over the other? Seems like defaults is always the better way to go: it reduces the amount of code and compiler overhead, but obviously I have no experience in this matter.

Edit: I, of course, researched before asking, but existing questions deal with specific issues/problems, whereas I'm trying to get a general understanding of how to think about C++.

T. Spikes
  • 141
  • 1
  • 11
  • 1
    A default parameter can only supply a value of the same type as a parameter. An overloaded function can use completely different parameters. That's just one difference. – Sam Varshavchik Apr 28 '19 at 14:16
  • 1
    Sometimes you want to use different parameter types for different overloads. – Cornstalks Apr 28 '19 at 14:16
  • 1
    When using `virtual` functions, default parameter behaviour can be *very* surprising (to both new and seasoned users). I'd definitely use overloading there. – Jesper Juhl Apr 28 '19 at 14:21

0 Answers0