我有一个班级状态和另一个朋友班级游戏。我的问题是,如果我有一个扩展 State 的类 MenuState,MenuState 也是 Game 的朋友吗?
编辑:
所以如果我有这样的情况:
class Game
{
private:
StateManager* myStateManager = new StateManager();
}
class State
{
public:
static void create(StateManager* Parent, const std::string name) {};
private:
StateManager* parent;
}
#define DECLARE_STATE_CLASS(T) \
static void create(StateManager* Parent, const std::string name) \
{ \
T* myState = new T(); \
myState->parent = Parent; \
Parent->manageState(name, myState); \
} \
class MenuState : State
{
public:
DECLARE_STATE_CLASS(MenuState)
}
int main()
{
Game app;
MenuState::create(This needs to be the stateManager in app, "MenuState");
app.init("MenuState");
}
我怎样才能在不公开状态经理的情况下完成这项工作?