- Jun 15, 2001
- 33,929
- 1,098
- 126
So I'm moving along in my personal C++ studies pretty well. I've written some successful code, examined other people's code, and I'm trying to start understanding why people would do certain things.
One thing I can't understand is the rationale behind operator overloading. I mean, I get what's nice about the concept: You want to be able to add two strings with
and you might like to multiply two matrices with
It just seems to me like this is a huge invitation for failure. Even if you use sane variable names
It still just seems nuts. Why not write a function
There's no possible confusion about what's happening there. Am I nuts? Is there something I'm not considering? It just seems... wrong.
Any thoughts?
One thing I can't understand is the rationale behind operator overloading. I mean, I get what's nice about the concept: You want to be able to add two strings with
Code:
str3=str1+str2
C=A*B
It just seems to me like this is a huge invitation for failure. Even if you use sane variable names
Code:
mtrxC=mtrxA * mtrxB
It still just seems nuts. Why not write a function
Code:
mtrxC.muleq(mtrxA,mtrxB)
There's no possible confusion about what's happening there. Am I nuts? Is there something I'm not considering? It just seems... wrong.
Any thoughts?
Last edited: