Andre Pang wrote: > Not necessarily... > > Like all powerful programming language features, operator overloading > can be used for good or for evil. People who work on and use maths > libraries greatly appreciate C++'s operator overloading's > capabilities.
Yep, I have quite a large library of linear algebra code written in C++ and for linear algebra I really appreciate being able to add two matrices together using: Matrix a = b + c ; What I don't like about C++ is that I am only allowed to overload existing operators and I'm not allowed to defined my own. For instance, for matrices it would make a lot of sense to have two product operators, '*' for regular matrix multiplication and a new operator '.*' for the matrix dot product. Ocaml does operators the other way. The built in operators cannot be overloaded, but new operators can be defined. I think this approach is a big improvement over C++. > Haskell, in particular, has great support for operator > overloading, and the language will ensure that you cannot abuse it > for things that aren't numeric. (In Haskell, you cannot actually > overload the + operator to concatenate two strings, for example -- a > common (ab)use of + that's present in a lot of dynamically typed > languages.) And Haskell does this even better than Ocaml :-). > (And, as Erik said, operator overloading has nothing to do with > dynamic typing.) Yeah, thats a bit clearer. The two things are completely orthogonal. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "There are only two things wrong with C++: The initial concept and the implementation." -- Bertrand Meyer _______________________________________________ coders mailing list [email protected] http://lists.slug.org.au/listinfo/coders
