yahoo5000 yahoo5000 - 20 days ago 5
C++ Question

Virtual function binding

Hello guys have a question about virtual function binding do not know if there is such a thing so i want to ask about this .
enter image description here

So i have a Game State machine. GameState class is a main class for all state entities , GameStateFirstPhase is a class for entity only for those other 3 classes (StartUp,SelectServer,ConnectServer).

So what do i want to do is to split a draw function and draw all entity of those 3 classes inside a GameStateFirstPhase class, and those 3 classes have their own draw function for only specific things that are for that class, like GameStateSelectServer class would have to draw a UI Select server panel + entity of all classes which is GameStateFirstPhase class.

This is how I want to bind CurrentState draw function with a GameStateFirstPhase Draw function: My game object have a pointer to a CurrentState and call it CurrentState Draw function .

I have tried to call a Entity class draw function inside CurrentState Draw function like this:

GameStateFirstPhase::Draw(gfx);


but i think that's illegal to do . I hope you get what i am trying to do and it makes sense . I also give image which i explain everything .

The question is if it possible to bind GameStateFirstPhase Draw function with a one of those states Draw functions (StartUp,SelectServer,ConnectSeerver state) bind i mean to get that parent behavior and add a child draw as well

Answer

"...bind i mean to get that parent behavior and add a child draw as well."

If you get around to asking about polymorphism, 'bind' is not the useable term. Research 'virtual', this is a modifier about a method.

No, the base class (parent) behavior (call it 'foo()') is not involved when a derived foo() is invoked. The derived foo() is not 'added' to the parent foo() in the sense of a sequence of method invocations.

However, the derived foo() can invoke the base foo(), at any point in its execution.