What Does “Overloaded”/“Overload”/“Overloading” Mean?

前端 未结 8 1204
清歌不尽
清歌不尽 2020-12-09 10:33

What does \"Overloaded\"/\"Overload\" mean in regards to programming?

相关标签:
8条回答
  • 2020-12-09 11:15

    It means having different versions of the same function which take different types of parameters. Such a function is "overloaded". For example, take the following function:

    void Print(std::string str) {
      std::cout << str << endl;
    }
    

    You can use this function to print a string to the screen. However, this function cannot be used when you want to print an integer, you can then make a second version of the function, like this:

    void Print(int i) {
      std::cout << i << endl;
    }
    

    Now the function is overloaded, and which version of the function will be called depends on the parameters you give it.

    0 讨论(0)
  • 2020-12-09 11:17

    Overloading is the poor man's version of multimethods from CLOS and other languages. It's the confusing one.

    Overriding is the usual OO one. It goes with inheritance, we call it redefinition too (e.g. in https://stackoverflow.com/users/3827/eed3si9n's answer Line provides a specialized definition of Draw().

    0 讨论(0)
提交回复
热议问题