Swig downcasting from Base* to Derived*
问题 I have the following c++ classes (simplified) which I am exposing to Python using SWIG: struct Component { virtual void update(); } struct DerivedComponent : public Component { void update() { cout << "DerivedComponent::update()" << endl; } void speak() { cout << "DerivedComponent::speak()" << endl; } } class Entity { public: Component* component(const std::string& class_name) { return m_components[class_name]; } private: std::unordered_map<std::string, Component*> m_components; } Now, in