id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 138,problem with overridable virtual functions in Boost.Python,nobody,david_abrahams,"{{{ I'm having problems overriding functions in Python with Boost. The examples provided on the website seem to work. However, all the examples I have managed to find have involved callback classes with virtual function overrides having zero arguments. I am trying to override functions with multiple arguments with no success. I get consistent errors when trying to manipulate multi-argument virtual functions polymorphically from a C++ extension. Im currently using Visual Studio .Net and Python 2.2.2. The following code demostrates the problem: ------------------Begin Code --------------------------- C++ code: #include #include class Entity { public: Entity() {Class = ""Entity""; } Entity(const Entity& e) { this->Class = e.Class; } std::string virtual GetClass(std::string PreFix) { return Class + PreFix; } public: std::string Class; }; class SimpleEntity : public Entity { public: SimpleEntity() { this->Class = ""SimpleEntity""; } SimpleEntity(const SimpleEntity& se) { this- >Class = se.Class; } std::string virtual GetClass(std::string PreFix) { return Class + PreFix; } }; #include #include #include #include #include #include using namespace boost::python; std::string Test(Entity* e, std::string PreFix) { return e->GetClass(PreFix); } class EntityWrap : public Entity { public: EntityWrap(PyObject* self_) : self(self_) {} EntityWrap(PyObject* self_, const Entity& e) : self(self_), Entity(e) {} std::string GetClass(std::string PreFix) { return call_method(self, ""GetClass"", PreFix); } std::string default_GetClass( Entity& e, std::string PreFix) { return e.Entity::GetClass(PreFix); } private: PyObject* self; }; class SimpleEntityWrap : public SimpleEntity { public: SimpleEntityWrap(PyObject* self_) : self(self_) {} SimpleEntityWrap(PyObject* self_, const SimpleEntity& se) : self(self_), SimpleEntity(se) {} std::string GetClass(std::string PreFix) { return call_method(self, ""GetClass"", PreFix); } std::string default_GetClass( SimpleEntity& se, std::string PreFix) { return se.SimpleEntity::GetClass (PreFix); } private: PyObject* self; }; BOOST_PYTHON_MODULE(hello) { class_(""Entity"") .def(init()) .def(""GetClass"", &EntityWrap::default_GetClass) .def_readwrite(""Class"", &Entity::Class); ; class_ >(""SimpleEntity"") .def(init()) .def(""GetClass"", &SimpleEntityWrap::default_GetClass) ; def(""Test"", Test); } Python Code: Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 Type ""copyright"", ""credits"" or ""license"" for more information. IDLE 0.8 -- press F1 for help >>> from hello import * >>> class DerivedEntity(SimpleEntity): def __init__(self): SimpleEntity.Class = ""DerivedEntity"" def GetClass(self,x): return self.Class + x >>> e = Entity() >>> Test(e, "" a test"") Traceback (most recent call last): File """", line 1, in ? Test(e, "" a test"") TypeError: bad argument type for built-in operation >>> s = SimpleEntity() >>> Test(s, "" a test"") Traceback (most recent call last): File """", line 1, in ? Test(s, "" a test"") TypeError: bad argument type for built-in operation >>> d = DerivedEntity() >>> Test(d, "" a test"") Traceback (most recent call last): File """", line 1, in ? Test(d, "" a test"") TypeError: bad argument type for built-in operation >>> e.Class 'Entity' >>> e.GetClass("" a test"") Traceback (most recent call last): File """", line 1, in ? e.GetClass("" a test"") TypeError: bad argument type for built-in operation >>> s.Class 'DerivedEntity' >>> s.GetClass(""a test"") Traceback (most recent call last): File """", line 1, in ? s.GetClass(""a test"") TypeError: bad argument type for built-in operation >>> d.Class 'DerivedEntity' >>> d.GetClass("" a test"") 'DerivedEntity a test' >>> ------------------End Code --------------------------- Am I missing something? Any help would be appreciated. Thanks, Vince }}}",Support Requests,closed,,python USE GITHUB,None,,Fixed,,