B
Brent Ritchie
Hello,
I have a problem that's really getting to me. I have an
std::vector, and it holds pointers to classes. From these classes I
need a refrence to the object that holds the vector, because it has the
information needed to perform certain functions on the objects in the
std::vector. for clarity I have an example.
class A
{
bool moveOK(B *b1, int x, int y);
std::vector<b*> listOfBClass;
};
class B
{
int x, y;
void move(int x, int y);
A *aRefrence; // Causes an error
};
B::move(int x, int y)
{
// how can I send the moveOK message?
}
As you can see I will get a bunch of errors saying stuff is undefined.
(All these classes are in different files, so I guess it creates a
circular dependency.) What I want to happen is I want to call the
moveOK method from within class B. The moveOK method looks through the
vector and finds if it is possible for the calling object to move, if
it returns true then the rest of the movement code is executed. Is
there a way to do this that is standard? I really don't want to resort
to hackish code, like using dynamic_cast when there is another way.
Also, if there is no "good" way to make this work can anyone suggest
another route? I can suppply more detail at request.
Thanks.
I have a problem that's really getting to me. I have an
std::vector, and it holds pointers to classes. From these classes I
need a refrence to the object that holds the vector, because it has the
information needed to perform certain functions on the objects in the
std::vector. for clarity I have an example.
class A
{
bool moveOK(B *b1, int x, int y);
std::vector<b*> listOfBClass;
};
class B
{
int x, y;
void move(int x, int y);
A *aRefrence; // Causes an error
};
B::move(int x, int y)
{
// how can I send the moveOK message?
}
As you can see I will get a bunch of errors saying stuff is undefined.
(All these classes are in different files, so I guess it creates a
circular dependency.) What I want to happen is I want to call the
moveOK method from within class B. The moveOK method looks through the
vector and finds if it is possible for the calling object to move, if
it returns true then the rest of the movement code is executed. Is
there a way to do this that is standard? I really don't want to resort
to hackish code, like using dynamic_cast when there is another way.
Also, if there is no "good" way to make this work can anyone suggest
another route? I can suppply more detail at request.
Thanks.