Questions tagged [overloading]

A type of polymorphism where different functions with the same name or different implementations of an operator are invoked based on the data types of the parameters passed. DO NOT USE FOR OVERLOADING IN PHP; THE MEANING OF THAT TERM IN PHP IS UNRELATED.

The terms overloading and overloaded may refer to:

Don't confuse it with

Related tags:

6857 questions
114
votes
17 answers

How to overload functions in javascript?

Classical (non-js) approach to overloading: function myFunc(){ //code } function myFunc(overloaded){ //other code } Javascript wont let more than one function be defined with the same name. As such, things like this show up: function…
Travis J
  • 81,153
  • 41
  • 202
  • 273
113
votes
10 answers

Is it possible to override a non-virtual method?

Is there any way to override a non-virtual method? or something that gives similar results (other than creating a new method to call the desired method)? I would like to override a method from Microsoft.Xna.Framework.Graphics.GraphicsDevice with…
zfedoran
  • 2,986
  • 4
  • 22
  • 25
113
votes
8 answers

What happens if I don't pass a parameter in a Javascript function?

I am new to the world of Javascript and am tinkering with writing very basic functions and stumbled upon the example below by accident and am unsure why it works when I am not passing a parameter when the function demands it. Sample…
PeanutsMonkey
  • 6,919
  • 23
  • 73
  • 103
112
votes
2 answers

Overload constructor for Scala's Case Classes?

In Scala 2.8 is there a way to overload constructors of a case class? If yes, please put a snippet to explain, if not, please explain why?
Felix
  • 8,385
  • 10
  • 40
  • 59
104
votes
19 answers

Can I override and overload static methods in Java?

I'd like to know: Why can't static methods be overridden in Java? Can static methods be overloaded in Java?
giri
  • 26,773
  • 63
  • 143
  • 176
103
votes
6 answers

Overloaded functions in Python

Is it possible to have overloaded functions in Python? In C# I would do something like void myfunction (int first, string second) { # Some code } void myfunction (int first, string second, float third) { # Some different code } And then…
Trcx
  • 4,164
  • 6
  • 30
  • 30
102
votes
7 answers

How to call a property of the base class if this property is being overwritten in the derived class?

I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties. But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then…
UncleZeiv
  • 18,272
  • 7
  • 49
  • 77
100
votes
11 answers

Overloading by return type

I read few questions here on SO about this topic which seems yet confusing to me. I've just begun to learn C++ and I haven't studied templates yet or operator overloading and such. Now is there a simple way to overload class My { public: int…
Shoe
  • 74,840
  • 36
  • 166
  • 272
98
votes
13 answers

Should you declare methods using overloads or optional parameters in C# 4.0?

I was watching Anders' talk about C# 4.0 and sneak preview of C# 5.0, and it got me thinking about when optional parameters are available in C# what is going to be the recommended way to declare methods that do not need all parameters specified? For…
Greg Beech
  • 133,383
  • 43
  • 204
  • 250
98
votes
8 answers

How is an overloaded method chosen when a parameter is the literal null value?

I came across this question in a quiz, public class MoneyCalc { public void method(Object o) { System.out.println("Object Verion"); } public void method(String s) { System.out.println("String Version"); } public static…
zakSyed
  • 1,364
  • 1
  • 13
  • 30
92
votes
3 answers

Why does the most negative int value cause an error about ambiguous function overloads?

I'm learning about function overloading in C++ and came across this: void display(int a) { cout << "int" << endl; } void display(unsigned a) { cout << "unsigned" << endl; } int main() { int i = -2147483648; cout << i << endl;…
infinite loop
  • 1,309
  • 9
  • 19
90
votes
4 answers

Typescript overload arrow functions

So we can do: export function myMethod (param: number) :number export function myMethod (param: string) :string export function myMethod (param: string | number): string | number { if (typeof param === 'string') { return param.toUpperCase() …
WHITECOLOR
  • 24,996
  • 37
  • 121
  • 181
89
votes
4 answers

c++ overloaded virtual function warning by clang?

clang emits a warning when compiling the following code: struct Base { virtual void * get(char* e); // virtual void * get(char* e, int index); }; struct Derived: public Base { virtual void * get(char* e, int index); }; The warning…
Jean-Denis Muys
  • 6,772
  • 7
  • 45
  • 71
85
votes
6 answers

Why does defining __getitem__ on a class make it iterable in python?

Why does defining __getitem__ on a class make it iterable? For instance if I write: class B: def __getitem__(self, k): return k cb = B() for k in cb: print k I get the output: 0 1 2 3 4 5 ... I would really expect to…
grieve
  • 13,220
  • 10
  • 49
  • 61
80
votes
4 answers

Why "avoid method overloading"?

Why does Jorge Ortiz advise to avoid method overloading?
missingfaktor
  • 90,905
  • 62
  • 285
  • 365