So I am creating a game with C++ and SDL.
I have a "gameobject" header file and no cpp (I do not need it) the game object has 2 functions void render() & tick().
The player class inherits from the gameobject. the problem is I don't know how to inherit functions. I tried virtual but I still can't figure it out.
I am used to Java so C++ is quite complicated.
My code:
gameobject.h :
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "game.h"
class gameobject
{
public:
virtual ~gameobject();
void virtual tick() = 0;
void render();
protected:
int width = pos.w;
int height = pos.h;
int posx = pos.x;
int posy = pos.y;
float velox;
float veloy;
SDL_Rect crop;
SDL_Rect pos;
};
#endif // GAMEOBJECT_H
player.h:
#ifndef PLAYER_H
#define PLAYER_H
#include "gameobject.h"
class gameobject;
class player : public gameobject
{
public:
private:
player(SDL_Renderer* renderer,int pwidth,int pheight);
~player();
};
#endif // PLAYER_H
player.cpp :
#include "player.h"
player::player(SDL_Renderer* renderer,int pwidth, int pheight)
{
this->pos.w = pwidth;
this->pos.h = pheight;
};
void player::tick(){} /// the problem here