Original Post
I have a class Object that can go into four states during my game. In each of these states i need to call some of the Objects methods. For example, in StateAttack, my object constantly looks around for something to move close to and attack. Am i meant to pass a pointer to the Object into each of the states? Check out my code sample and comments for exactly what i mean. BTW Object can not be a singleton, as i will have many instances.
class Object
{
some methods
some members
void Update(float dt);
std:vector<State*> states;
}
void Object::Update(float dt)
{
for(all states)
state->Update(dt);
// here is my problem, the state class will know nothing about class Object
// so it cannot
}
// assume StateAttack is derived from some base State class
void StateAttack::Update(float dt)
{
// does not have access to class Object's
// members or methods so cannot implement the effects
// of the state on class Object
// how do you get round this? pass a reference of or a pointer?
// are you meant to update class Object's here
}