QT Creator - Definition of implicity-declared 'player::player()'

Sorry for posting so many posts asking for help, but I’m a newbie when it comes to OF!

I’m getting this error when I’m trying to run my code:

It points me to my player.cpp file, which just contains the following:

I’m assuming that it’s something related to my player.h file, so I will also include that below too:
(Thanks for any help!)

#ifndef PLAYER_H
#define PLAYER_H
#include "ofMain.h"

class player

    //This stores the player's position in an ofPoint.
    ofPoint pos;

    //Used to store the height width and speed variables for the player.
    float height, width, speed;
    //Int used for lives to ensure that lives are always a full number.
    int lives;

    //These bools check to see what inputs are currently pressed.
    //Using bools as OpenFrameworks has issues detecting multiple inputs
    bool is_left_pressed, is_right_pressed, is_down_pressed, is_up_pressed;

    void setup(ofImage * _img);
    void update();
    void draw();
    void shoot();

    void calculate_movement();

    bool check_can_shoot();

    //points towards the sprite for the player.
    ofImage * img;

#endif // PLAYER_H


Just remove



from the .cpp file.

The error is basically saying this function ( a special function called a constructor ) wasn’t defined in the class header.

Another solution would be to add this line to the .h

class player
    player(); //define the constructor function 

but I usually recommend not having a constructor so the first solution would be my suggestion


1 Like