Please, someone, this is so hard, explain LINE by LINE please, what each thing does etc
>>55044596
no, use google and wikipedia
If I have something, of type "string"
What does adding them together mean?
Does it mean that I want to add each individual character's byte value together numerically? Of course not, that's retarded.
It means "concatenate"- place one after another and give me a new copy. "Fuck " + "you" becomes "Fuck you"
If you were implementing your own string class from scratch, you would need to overload the + operator to do concatenation for strings.
>>55044596
standard operator does one thing
write a function with the same name
function does another thing
now operator does another thing
>>55044596
> this is so hard
It's not hard, you are just stupid.
Overloading means you give a symbol a new meaning.
For example you make 3d-objects a = (1,2,3) and b = (4,5,6), you can overload the "+" operator so you can add them like that:
c = a + b
Now do your own reasearch, fag.
CONDUCTOR
>>55044621
Off-topic from the main question, wouldn't operator overriding be a more appropriate term for this idea?
>>55044775
It's overriding from the type's perspective (you override the behaviour it exhibits when that operator is applied to it), but from the operator's perspective it's overloading because it can still exhibit its old behaviour for different types.
I'd guess that's the reason for the naming at least.
>>55044596
>Please, someone, this is so hard, explain LINE by LINE please, what each thing does etc
Ok, take for example
BigInt operator++(){
return (*this)+=1;
}
>BigInt
return type
>operator++
Which operator I want to overload. The word "operator" is prefixed to make compiler writers' lives easier.
>()
empty means it's the prefix version. (int dummy) would be the postfix version.
>return
What I'm giving back
>(*this)
the class I'm incrementing accessed by the "this" pointer
>+=
add the right to the left and overwrite the left value operator
>1
The number after 0
>;
End of instruction marker
>{ ... }
The code block