Cameron Ball
Cameron Ball

Reputation: 4128

Access method of class within class

I'm trying to port some code from an older version of a program to a newer version and some things have moved. There is a class called 'Game', and it USED to contain a method called ButtonNameToIndex, however in the newer version there is now a class inside the Game class, called 'InputScheme', and ButtonNameToIndex is declared in InputScheme

Game.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;
}

The code I am trying to port looks like this:

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

I can't work out how to access ButtonNameToIndex now that it has moved to a new class.

Upvotes: 0

Views: 91

Answers (1)

Dan
Dan

Reputation: 13412

Since the Game class has a public member variable of type InputScheme you can replace any calls to

pGame->ButtonNameToIndex("Operator")

with

pGame->m_InputScheme.ButtonNameToIndex("Operator")

we use -> to access the member of Game since we are accessing through a pointer (I assume), since m_InputScheme is a value (not pointer) we access its member function using the . operator

Upvotes: 4

Related Questions