C ++继承和类的新实例

时间:2014-10-02 20:16:57

标签: c++ inheritance

我有以下标题和类:

game.h:

#include "GameStateManager.h"
class game
{
    //bunch of lines here
}

GameStateManager.h

#include "GameState.h"
class GameStateManager
{
    //bunch of lines here
}

GameState.h

class GameState
{
    //bunch of lines here
}

PlayState.h

#include "GameState.h"
class PlayState : public GameState
{
    //bunch of lines here
}

我需要在' game.cpp'中创建一个新的PlayState实例。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

假设您正在使用标题保护#pragma once,只需:

#include "GameStateManager.h"
#include "PlayState.h"
class game
{
    PlayState play_state;
    //bunch of lines here
}