❔ operator * cannot be applied to operands of type T and T
I'm getting this error:
operator * cannot be applied to operands of type T and T
operator * cannot be applied to operands of type T and T
I understand why, but I'm wondering if there's a way to add a constraint only to ints , floats and doubles. Sounds like it's a no. What else can be done?
struct Vector2D<T> { public T x, y; public Vector2D() { x = y = default(T); } public Vector2D(T xPos, T yPos) { x = xPos; y = yPos; } public T GetMagnitude() { return System.Math.Sqrt(x * x + y * y); // error } }
struct Vector2D<T> { public T x, y; public Vector2D() { x = y = default(T); } public Vector2D(T xPos, T yPos) { x = xPos; y = yPos; } public T GetMagnitude() { return System.Math.Sqrt(x * x + y * y); // error } }