【问题标题】:Access method of class within class类内类的访问方法
【发布时间】:2012-11-08 12:02:11
【问题描述】:

我正在尝试将一些代码从旧版本的程序移植到新版本,并且有些东西已经移动。有一个名为“Game”的类,它曾经包含一个名为 ButtonNameToIndex 的方法,但是在较新的版本中,Game 类中现在有一个名为“InputScheme”的类,并且在 InputScheme 中声明了 ButtonNameToIndex

游戏.h:

class Game
{
public:
   const char *     m_szName;
   const Style * const* m_apStyles;
   bool         m_bCountNotesSeparately;
   bool         m_bAllowHopos;
   InputScheme      m_InputScheme;
}

InputScheme.h:

class InputScheme
{
public:
    const char  *m_szName;
    int     m_iButtonsPerController;
    struct GameButtonInfo
    {
        const char  *m_szName;
        GameButton  m_SecondaryMenuButton;
    };

    GameButtonInfo m_GameButtonInfo[NUM_GameButton];
    const InputMapping *m_Maps;

    GameButton ButtonNameToIndex( const RString &sButtonName ) const;
}

我尝试移植的代码如下所示:

FOREACH_ENUM( GameButton, pGame->ButtonNameToIndex("Operator"), gb )
    ini.SetValue( sPlayerKey, GameButtonToString(pGame, gb),
        FromMapping(mapping.m_iGameLights[gc][gb]) );

现在我不知道如何访问 ButtonNameToIndex,因为它已移至新类。

【问题讨论】:

    标签: c++ class nested-class


    【解决方案1】:

    由于Game 类有一个InputScheme 类型的公共成员变量,您可以替换任何对

    的调用
    pGame->ButtonNameToIndex("Operator")
    

    pGame->m_InputScheme.ButtonNameToIndex("Operator")
    

    我们使用-> 访问Game 的成员,因为我们通过指针访问(我假设),因为m_InputScheme 是一个值(不是指针),我们使用. 运算符访问它的成员函数

    【讨论】:

      猜你喜欢
      • 2011-07-27
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      相关资源
      最近更新 更多