Object created in one class, needs to use variables in the class it was created in

Started by
2 comments, last by phil_t 7 years, 10 months ago

I'm having a problem where I create a object of my Input class in my MainGame class, but the Input object needs to change multiple variables inside my MainGame class, how would I go about doing that?

Some things that I have though of so far are :

  • Making the variable inside MainGame static - (Does not work since non-static functions need to use it)
  • Sending it to the Input constructor when I create it - (Prefer not to do this, since I would need to do this with multiple variables, causing a mess when creating the object)

So, any other ideas on how to fix this problem?

Advertisement

Have the MainGame update itself based on state reported by the Input object?

Have the MainGame register callbacks on the Input object so the Input object can ask the MainGame to update itself?

Use a message-passing protocol to communicate state between object?

Stephen M. Webb
Professional Free Software Developer

What are those variable you want to change?
Seems to me you decided on the wrong design for that part.

What is the responsibility of your Input class?

This topic is closed to new replies.

Advertisement