Kind of confused as to how I should implement a simple entity hierarchy in OOP style C. For example, here's the equivalent C++ code:
class Entity {
protected:
float x, y;
Entity(float x, float y) : x(x), y(y) { }
virtual void update() = 0;
virtual void render() = 0;
virtual ~Entity() { }
};
class Player : public Entity {
Player(float x, float y) : Entity(x, y) { }
void update() {
}
void render() {
}
};
So right now I have a structure Entity that has two function pointers that will point to the update and render functions. Then I would have a Player structure which would have a pointer to the Entity structure so it can access the members. One thing I'm kind of confused about is how allocation would work... would I have a new_entity function perhaps that allocates an Entity structure? Could I have a new_player function that allocates an Entity ptr, and returns the Player structure, and will set the functions to point to the player_update, play_render functions, etc?