why am I getting "no matching function call to constructor vector2d.h"

Why am I getting thie following error when trying to compile this game engine code, the previous example in my book compiled fine and all Ive done is add another variable "m_acceleration" and a function call "m_acceleration.setX(1)"

$ g++ -c Enemy.cpp Game.cpp GameObject.cpp main.cpp Player.cpp SDLGameObject.cpp TextureManager.cpp -lSDL2 -lSDL2_image
SDLGameObject.cpp: In constructor ‘SDLGameObject::SDLGameObject(const LoaderParams*)’:
SDLGameObject.cpp:6:82: error: no matching function for call to ‘Vector2d::Vector2d()’
eObject(pParams), m_position(pParams->getX(), pParams->getY()), m_velocity(0,0)
^
In file included from SDLGameObject.h:7:0,
from SDLGameObject.cpp:1:
Vector2d.h:10:2: note: candidate: Vector2d::Vector2d(float, float)
Vector2d(float x, float y) : m_x(x), m_y(y) {}
^~~~~~~~
Vector2d.h:10:2: note: candidate expects 2 arguments, 0 provided
Vector2d.h:7:7: note: candidate: constexpr Vector2d::Vector2d(const Vector2d&)
class Vector2d
^~~~~~~~
Vector2d.h:7:7: note: candidate expects 1 argument, 0 provided
Vector2d.h:7:7: note: candidate: constexpr Vector2d::Vector2d(Vector2d&&)
Vector2d.h:7:7: note: candidate expects 1 argument, 0 provided


main.cpp https://pastebin.com/YVHM31WL
Enemy.h https://pastebin.com/ed4pRGCV
Enemy.cpp https://pastebin.com/jH1Zb2G7
Game.h https://pastebin.com/EfkcCvit
Game.cpp https://pastebin.com/JbAdzssK
GameObject.h https://pastebin.com/rkPpsB7m
GameObject.cpp https://pastebin.com/ci4ssPkw
LoaderParams.h https://pastebin.com/6jtR4386
Player.h https://pastebin.com/jknCWM6j
Player.cpp https://pastebin.com/F2nUb81d
SDLGameObject.h https://pastebin.com/4JR9SA4e
SDLGameObject.cpp https://pastebin.com/M5cU5PX3
TextureManager.h https://pastebin.com/Vc8LmwEe
TextureManager.cpp https://pastebin.com/tHPqcb7n
Vector2d.h https://pastebin.com/3vyB5dCJ
Your SDLGameObject defines the following member variables:
1
2
3
4
5
6
7
8
9
10
11
12
13
    Vector2d m_position;
   
    int m_width;
    int m_height;
   
    int m_currentRow;
    int m_currentFrame;
   
    std::string m_textureID;
   
    Vector2d m_velocity;
   
    Vector2d m_acceleration;


But your constructor does:
1
2
SDLGameObject::SDLGameObject(const LoaderParams* pParams) :
GameObject(pParams), m_position(pParams->getX(), pParams->getY()), m_velocity(0,0)

You didn't specify m_acceleration in the initializer list, so it is default constructed.

But... Vector2d does not have a 0-arg constructor defined, so it fails.

Try adding:
, m_velocity(0,0), m_acceleration(0,0)
Registered users can post here. Sign in or register to post.