0

I have a 2D vector class and I have a function that multiplies vectors, one the adds, divides, ect. I was wondering if instead of calling a function, if it would be possible to control what happens when I use *,/,+, or - . For example, could I have:

vector1 * vector2

do the same thing as

multiplyVectors(Vector1, Vector2)
4

1 回答 1

4
public class Vector2D
{
    // ...

    public static Vector2D operator * (Vector2D v1, Vector2D v2)
    {
        return multiplyVectors(v1, v2);
    }
}
于 2013-06-14T05:08:46.437 回答