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++.

3
  • 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. Commented Apr 28, 2019 at 14:16
  • 1
    Sometimes you want to use different parameter types for different overloads. Commented Apr 28, 2019 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. Commented Apr 28, 2019 at 14:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.