I am trying to make a constructor for my Input class I get this error:
Severity Code Description Project File Line Suppression State Error (active) E0291 no default constructor exists for class "Vector2" RunGameEngine C:\Users\imman\source\repos\RunGameEngine\RunGameEngine\Run\Input.cpp 5
for some reason intelisense wants me to create a default constructor for Vector2 even though I have one for it.
Input.h:
#pragma once
#include <GLFW/glfw3.h>
#include "Vector.h"
#include "Window.h"
class Input
{
public:
Input(GLFWwindow* window);
bool isKeyPressed(float key);
Vector2 getMousePos();
private:
bool m_keys[348];
Vector2 m_mousePos;
GLFWwindow* m_window;
};
Input.cpp:
#include "Input.h"
Input::Input(GLFWwindow* window)
{
m_window = window;
}
Vector2 Input::getMousePos()
{
glfwGetCursorPos(m_window, &m_mousePos.x, &m_mousePos.y);
return m_mousePos;
}
bool Input::isKeyPressed(float key)
{
return false;
}
Vector.h:
#pragma once
struct Vector2
{
double x, y;
Vector2(double x, double y)
{
this->x = x;
this->y = y;
}
};
struct Vector3
{
double x, y, z;
Vector3(double x, double y, double z)
{
this->x = x;
this->y = y;
this->z = z;
}
};
I would do
Vector2 Input::getMousePos()
{
double Pos_x;
double Pos_y;
glfwGetCursorPos(m_window, &Pos_x, &Pos_y);
return Vector2(Pos_x, Pos_y);
}
and just skip the m_mousePos member. You don't really want to save that anyway, do you?
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.