C++继承和类的新实例
C++ Inheritance and new instance of a class
我有以下标题和类:
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实例。我该怎么做?
假设您使用的是头保护或#pragma once
,那么简单地说:
#include "GameStateManager.h"
#include "PlayState.h"
class game
{
PlayState play_state;
//bunch of lines here
}
相关文章:
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 根据参数创建派生类的新实例
- 我们可以在没有新实例化的情况下声明一个抽象方法来返回抽象超类中的子类对象吗
- 基于现有实例创建类的新实例
- 将unordered_map的新实例插入到unordered_map中
- 如何自动生成结构的新实例
- 在C 中,是否有一种(新的)方法来测试类是否在模板中具有虚拟破坏者而无需实例化实例
- 如何使递归函数在进入下一级循环之前读取每个新实例
- 为什么方法应该返回新实例,而不是修改实例本身
- C 函数中的新实例
- 正确的编码:返回类的新实例时
- 如果我在一个类中有一个静态属性,并创建该类的许多新实例
- 在 C 中声明结构的新实例
- 如何检查是否存在单例实例,如果没有,则不创建新实例?
- malloc是否创建该类的新实例
- 返回矢量的新实例
- "错误:需要类型"创建新实例
- 如何防止其他人在堆上创建类的新实例
- 使用模板创建类的新实例,不知道如何处理错误
- 尝试使用模板创建类的新实例,意外错误