Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我有以下标题和类:

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
}


播放状态

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


我需要在“ game.cpp”中创建PlayState的新实例。我怎样才能做到这一点?

最佳答案

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

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

关于c++ - C++继承和类的新实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26168931/

10-09 08:49