c26451 overflow error

Asked 2 years ago, Updated 2 years ago, 103 views

Vector2(float _x = 0.0f, float _y = 0.0f) : : x(_x), y(_y) {}

float Magnitude() { return (float)sqrt(x * x + y * y); }

There was an overflow error in return, but I don't know why it's a problem or how to fix it.

c++ overflow

2022-09-20 19:32

1 Answers

I rewatched it, but there's no error

#include <iostream>

using namespace std;

class Vector2
{
public:
    Vector2(float _x = 0.0f, float _y = 0.0f) : x(_x), y(_y) {}
    float Magnitude() { return (float)sqrt(x * x + y * y); }
private:
    float x{ 0 };
    float y{ 0 };
};

int main()
{
    Vector2 a;
    Vector2 b{ 3,-3 };
    Vector2 c{ numeric_limits<float>::max(),numeric_limits<float>::max() };

    cout << a.Magnitude() << '\n';
    cout << b.Magnitude() << '\n';
    cout << c.Magnitude() << '\n';
}


2022-09-20 19:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.