To view parent comment, click here.
To read all comments associated with this story, please click here.
Correct me if I'm wrong, but :
Standard C++ regulates, that the compiler can
only generate the copy constructor, the default constructor and the assignment operator, if they are not implemented. In any other case, including the operator+(), one has to implement the operator explicitly, like you would have to with functions.
If you have something a la
foo a;
bar b;
foobar c( a + b );
in your code, you have either to look for
foobar foo::operator+( bar const& rhs );
or
foobar operator+( foo const& lhs, bar const& rhs);
in your header files. Besides the inconvenience to look potentially for this two different notations, instead of one in case of a hypothetical plus() function, I can see little problems here.
Assuming one uses operator overloading only where it is justified (e.g. to translate arithmetic or gramatical operations like concatination into code), it is imho supperior to functions. I write numerical code for scientific applications, and at least I find
foobar d( a * b + c );
easier to read/maintain/understand than for example
foobar d( plus( prod( a , b ) , c );
Programmers, who abuse operator overloading should be treated with the proverbial clue bat, agreed. But operator overloading can, just like expression template metaprogramming, give you a very handy tool, that saves time and effort und is a joy to use.
Like every tool, it can be misused, though. but just because some developers choosed to obfuscuate the meaning of their programs by using operators, I don't see a reason to bash operator overloading.
Regards
EDIT: foobar c() -> foobar d() in the second and third example, sorry :-)
Edited 2006-12-04 19:55
First i didn't mean to write debugger, i meant when i am reading the code.
Operator overloading makes it harder for other people to understand your code.
The example you gave above could simply be:
x = calcMultiply(a, b);
x = CalcSum(x, c);
d(x)
What is wrong here, it is more clear and when you are reading the code, you immediately know that multiply is not simply an arithmatic multiplication.
I like to write code which the programmer can understand when they are reading it. Ambiguity is something that i hate and C++ has many constructs that are ambiguous.







Member since:
2005-07-10
When you are debugging at least you know they are a function call.
How the hell do you know if + is a function call unless ofcourse you plan to make all operators overloaded?