Riellia Hionmet
Riellia Hionmet

Reputation: 33

Create diferent childs struct that expand a function of a parent struct, and pass the child object in another function. C++

I'm creating diferent Child Structs with a diferent implementation of a function, starting with a base Parent function.

I want a general reference to call the function of a Child in another struct as a pointer. Then change to another child struct and call the function of the new child.

struct State{
   virtual void Update(){
   }
};


struct IdleState : State{
    void Update (bool* var){
        //some code
    }
};

struct StateMachine{
    State* currentState;
    void Initialize(State* newState){
        currentState = newState;
    }
    void Update(){
        currentState.Update();
    }
};

Upvotes: 0

Views: 47

Answers (0)

Related Questions