Questions tagged [overload]

Overloading is used to create multiple methods of the same name with different implementations.

Overloading is used to create multiple methods of the same name with different implementations. Also named function overloading or method overloading it can be used to perform context specific task based upon the parameters called within the function or method. The type of overloading can vary either by number of parameters called or data type.

14 questions
86
votes
15 answers

I don't understand the arguments against operator overloading

I just read one of Joel's articles in which he says: In general, I have to admit that I’m a little bit scared of language features that hide things. When you see the code i = j * 5; … in C you know, at least, that j is being multiplied by five and…
fredoverflow
  • 6,854
  • 8
  • 39
  • 46
63
votes
6 answers

Why is the minus sign, '-', generally not overloaded in the same way as the plus sign?

The plus sign + is used for addition and for string concatenation, but its companion: the minus sign, -, is generally not seen for trimming of strings or some other case other than subtraction. What could be the reason or limitations for…
Digvijay Yadav
  • 685
  • 1
  • 5
  • 10
5
votes
3 answers

I want to overload a function with the same type parameter; what should I do?

I'm creating an API, and I want to overload a function for strip: QString MyClass::strip(); QString MyClass::strip(QRegularExpression open); QString MyClass::strip(QRegularExpression close); QString MyClass::strip(QRegularExpression open,…
Anon
  • 3,565
  • 3
  • 27
  • 45
4
votes
2 answers

Can a function be polymorphic and overloaded?

In Graham Hutton's book "Programming in Haskell", he defines a function to be polymorphic, if its type "contains one or more type variables". He then defines a function to be overloaded, if its type "contains one or more class constraints". From…
Ryan Smith
  • 151
  • 5
4
votes
1 answer

Etymology of (function) overloading

Where does the phrase "overload" come from? It's interesting to see the translation of the term in different languages (e.g. list of Wikipedia articles about overloading), some languages translate it directly (in the meaning of "to put too much…
hunyadym
  • 151
  • 5
3
votes
4 answers

Need help understanding reference operator(C++) in specific functions

In the current semester at the university we are working on OOP with C++. I would like to understand the difference between a pointer and a reference operator. The differences that I understand are: 1. Cannot change the object that the reference…
Chris
  • 161
  • 1
  • 1
  • 5
2
votes
2 answers

Is implementing operator overloading with variable arity possible?

Implementing operator overloading for e.g. + (plus) isn't terribly difficult if you know it's a binary operator. One can just parse expression + expression But what if the programmer can choose whether + is binary, unary (prefix/postfix), part of a…
Mark
  • 662
  • 5
  • 12
1
vote
2 answers

Does changing the private member of a class through an overloaded subscript operator break encapsulation?

I have always been taught that in order to in-keep with encapsulation objects should be responsible for performing calculations on their own data. So in this case here is this breaking rules of encapsulation and considered bad practice? #include…
ohkneel
  • 13
  • 3
1
vote
1 answer

Java Overloading/Inheritance

I've been trying to get a clear understanding of what the end of the follwing code outputs: class C { public int foo(C p) { return 1; } } class D extends C { public int foo(C p) { return 2; } public int foo(D p) { return 3; } } C p = new…
TacoB0t
  • 153
  • 5
0
votes
2 answers

Could Java XYZ implement (limited) Operator Overloading without breaking backwards compatibility?

Recently, I've been learning a bit more of C++ and the dangers and uses of operator overloading, and the readability boost it provides to arithmetic types (like Complex numbers). A while ago, I was playing around with Rust, and I really liked how…
Alxe
  • 113
  • 1
0
votes
1 answer

Overloading to support multiple related types (especially pointers)

Problem I was just trying to debug a set of file-manipulation routines I wrote for a program I am working on. One of them kept returning an INVALID_HANDLE error. Explanation I figured out what the problem was. It turns out that because I provided…
Synetech
  • 395
  • 1
  • 4
  • 15
0
votes
1 answer

Overloading Operators - C++

I was experimenting with new overloaded operators, I have created one void operator and another one that returns something when it's called: #include struct chichachicha{ int operator()(){ return 25; }; }; struct…
user827992
  • 1,175
  • 2
  • 9
  • 19
-1
votes
1 answer

Preventing name collision between user-defined modules within a framework

I'm a contributor to a framework that's designed for producing synthetic data. The system allows the end-user to create custom data generators and load them into the framework. Currently we store the available generators in a dictionary. We then…
user362470
-3
votes
1 answer

Should absolute value functions be overloaded to give the norm of vector-like data structures?

The absolute value function is an instance of the norm function in one dimension. I've seen instances of libraries where the absolute value function is overloaded to also take the norm of higher dimensional vectors. Would it be better practice to…
Josie Thompson
  • 271
  • 2
  • 6