#no matching function for call to

18 messages · Page 1 of 1 (latest)

shut mauve
#

I'm pretty sure the error is saying that I have no constructor which takes in no parameters, but I'm not even trying to call such a constructor in the first place.

//Vector2.h
#pragma once

class Vector2
{
    public:
        float x, y;

        Vector2(float x, float y) ;
        Vector2 Normalize();

        Vector2 operator+(const Vector2 rhs);
        Vector2 operator-(const Vector2 rhs);
};
//Vector2.cpp
#include <iostream>
#include "Vector2.h"

Vector2::Vector2(float x, float y)
{
    this->x = x;
    this->y = y;
}

Vector2 Vector2::Normalize()
{
    float lengthSq = x * x + y * y;
    if (lengthSq > 0.0f) {
        float invLength = 1.0f / std::sqrt(lengthSq);
        return Vector2(
            x *= invLength,
            y *= invLength
        );
    }
}

Vector2 Vector2::operator+(Vector2 rhs)
{
    this->x += rhs.x;
    this->y += rhs.y;
}

Vector2 Vector2::operator-(Vector2 rhs)
{
    this->x -= rhs.x;
    this->y -= rhs.y;
}
languid briarBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

hearty turret
#

The pointer is on the wrong side

shut mauve
#

nvm

#

other thing errored below

#

ty

#

!solved

languid briarBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

hearty turret
#

np

agile ermine
shut mauve
#

new to c++

#

a lot of ways to do the same thing (pretty much) and i dont really know the difference

agile ermine
#

aww poor thing

#

pro tip: c++ isn't java, don't use new

#
Vector2 player{ 0.0f, 0.0f };```
#

there you go

#

new creates an object on the heap and then delegates the responsibility of lifetime management to YOU, which is 99% of the cases what you don't want