Class declarations
I have a question on class declarations. How do you allow two classes to have objects of each other? For example, I'm have a two classes in a header file, BaseState class and StateManager class. The BaseState class is declared first in the file and accepts a StateManager object in one or more function parameters. My compiler complains that is it doesn't know about the StateManager object yet because it hasn't gotten to the StateManager declaration. I can't move the StateManager declaration because one or more of it's functions accept a BaseState object.
How do you make this work aside from putting the declarations in seperate header files, I would like to keep them in the same? Is this possible? Thanks.
Declare it first. Something like this:
class BaseState;
class StateManager {
// ...
};
class BaseState {
// ...
};
class BaseState;
class StateManager {
// ...
};
class BaseState {
// ...
};
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement