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)
public class Vector2D
{
// ...
public static Vector2D operator * (Vector2D v1, Vector2D v2)
{
return multiplyVectors(v1, v2);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.