C++ 从接口强制转换到实现接口的类的子类
在我们的项目中,我们有一个Models_Manager类,其中包含IGameObjects的映射C++ 从接口强制转换到实现接口的类的子类,c++,casting,C++,Casting,在我们的项目中,我们有一个Models_Manager类,其中包含IGameObjects的映射 std::map<std::string, IGameObject*> gameModelList; 稍后我们想再次访问球体。要做到这一点,我们希望从IGameObject到球体进行投射。怎么用?多谢各位 继承: class Sphere : public Models::Model class Model :public IGameObject 看起来我需要使用动态
std::map<std::string, IGameObject*> gameModelList;
稍后我们想再次访问球体。要做到这一点,我们希望从IGameObject到球体进行投射。怎么用?多谢各位
继承:
class Sphere : public Models::Model
class Model :public IGameObject
看起来我需要使用动态投影
Models::Sphere* spherecast = dynamic_cast<Models::Sphere*>(gameModelList["fireball"]);
Models::Sphere*spherecast=dynamic_cast(gameModelList[“fireball”]);
看起来我需要使用动态\u cast
Models::Sphere* spherecast = dynamic_cast<Models::Sphere*>(gameModelList["fireball"]);
Models::Sphere*spherecast=dynamic_cast(gameModelList[“fireball”]);
您可以使用dynamic\u cast
执行此操作。您可以使用dynamic\u cast
执行此操作。