Re: Operator Overloading (Was: In Praise of Strong Typing)
by Daniel Pitts <newsgroup.spamfilter@[EMAIL PROTECTED]
>
Jun 22, 2008 at 09:43 PM
Bartlomiej Golenko wrote:
> Daniel Pitts <newsgroup.spamfilter@[EMAIL PROTECTED]
> wrote:
>> This is not bad code (albeit C++ code)
>> Vector operator+(const Vector &left, const Vector &right) {
>> Vector result;
>> for (int i = 0; i < Vector::size; ++i) {
>> result[i] = left[i] + right[i];
>> }
>> return result;
>> }
>> ...
>> myNewVect = someVect + someOtherVect;
>
> Its pure evil. Consider this:
>
> myNewVect = someVect * someOtherVect;
>
> What kind of product is it ?
> - inner product ?
> - tensor product ?
> - cross product ?
> - carthesian product ?
>
> The fact that YOU know exactly how did you overload operator* does
> not necessarily mean everyone else does as well.
>
> Regards, BG
>
Did I overload the * operator in this example? No.
"*" make sense for vector * scalar or scalar * vector in the general
case, but the "*" glyph for vector (X) vector doesn't make well-defined
sense.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>