C++ 必须传递大量关于使用继承的信息,我是否正确地使用了它?

C++ 必须传递大量关于使用继承的信息,我是否正确地使用了它?,c++,inheritance,C++,Inheritance,在基于回合的战斗游戏中,角色可以执行的所有动作都继承自该类。一开始是这样的: using ActionPtr = std::shared_ptr<Action>; class Action { public: Action(Entity actor, std::uint32_t time) { ... } virtual ActionPtr execute() = 0; ... std::uint32_t time; // time that the action will occu

在基于回合的战斗游戏中,角色可以执行的所有动作都继承自该类。一开始是这样的:

using ActionPtr = std::shared_ptr<Action>;
class Action {
public:
Action(Entity actor, std::uint32_t time) { ... }
virtual ActionPtr execute() = 0;
...
std::uint32_t time; // time that the action will occur. For e.g 10 if it occurs in tick 10 of combat
    Entity actor; // the character performing the action
    };
sortTimeline();
ActionPtr followUpAction = timeline.front()->execute();
timeline.removeFront();
timeline.push_back(followUpAction);
例如,执行的AiDecideAction返回后续操作(即该实体选择执行的操作)。攻击动作的执行将返回一个决定动作集,该动作集将在依赖于攻击的冷却时间后发生。这些操作将在下一次勾选中添加和处理

由于动作可以创建其他动作,我发现我必须将动作可能需要执行的所有可能信息推送到动作类,即继承层次结构的根。这是为了它能够正确地构建后续行动。例如

AttackAction::execute() {
...
return ActionPtr(new AiDecide(actor, nextActionTime, allies, enemies);
 // allow this entity to decide what to do after attacking
}
攻击行动需要接近盟友和敌人,以便提供给建设者;因此,我最终修改了Action的构造函数,以获取派生操作可能需要的所有可能信息,从而尝试解决此问题

有更好的方法吗?我想知道继承是否是建模这个问题的正确方法。我不得不多次修改所有操作,以便提供构建其他操作所需的信息,这并不理想