Stewart Gordon wrote:
[color=blue]
> While it was 4/12/03 1:20 pm throughout the UK, Karl Heinz Buchegger
> sprinkled little black dots on a white screen, and they fell thus:
>
> <snip>
>[color=green]
>> There is a simple rule when it comes to operator overloading: Do as
>> int does. This means: Try to implement operators in a way as you
>> would implement them for int (if you could). In principle you can
>> create a class, which has an operator+ which does the equivalent of
>> multiplication. But this would be confusing, cause everybody reading
>> a + b thinks of addition and not of multiplication. That's what is
>> ment with: Do as int does.[/color]
>
> <snip>
>
> That makes sense. Shame someone didn't invent an operator that means
> concatenation, leaving std::string stuck with +. (My hat goes off (not
> that I ever have any reason to wear one) to D, which has introduced ~ as
> a binary op for this purpose.)
>
> A related question is what operator should be overloaded to represent
> the dot product of vectors, particularly if you want to implement cross
> product as well. I've been using % for this, for want of a better
> option....
>
> Stewart.
>[/color]
I prefer the FORTRAN concept: create explicit functions when no
operator exists. So given three vectors, the dot product becomes:
result = dot_product(vector_a, vector_b);
Rather than
result = vector_a % vector_b;
or
result = vector_a . vector_b;
or
result = vector_a * vector_b;
or
result = vector_a *. vector_b;
This issue seems to be one of typing rather than readability
or clarity.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book