|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Python, virtual inheritance and directorsHello,
suppose I have two classes like this and turn on directors for the derived one: class BaseClass { BaseClass(int a); }; class MyClass : virtual public BaseClass { public_ MyClass( int a ); }; %feature("director") MyClass; The code swig will generate looks like SwigDirector_MyClass::SwigDirector_MyClass(PyObject *self, int a): MyClass(a), Swig::Director(self) { ... } This fails to compile, because it should look like SwigDirector_MyClass::SwigDirector_MyClass(PyObject *self, int a): MyClass(a), BaseClass(a), Swig::Director(self) { ... } Notice the additional call to the BaseClass(int) constructor. How can I tell swig to insert BaseClass(a) there? -Matthias ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Re: Python, virtual inheritance and directorsNitro wrote:
> Hello, > > suppose I have two classes like this and turn on directors for the derived > one: > > class BaseClass > { > BaseClass(int a); > }; > > class MyClass : virtual public BaseClass > { > public_ > MyClass( int a ); > }; > > %feature("director") MyClass; > > The code swig will generate looks like > > SwigDirector_MyClass::SwigDirector_MyClass(PyObject *self, int a): > MyClass(a), Swig::Director(self) > { ... } > > This fails to compile, because it should look like > > SwigDirector_MyClass::SwigDirector_MyClass(PyObject *self, int a): > MyClass(a), BaseClass(a), Swig::Director(self) > { ... } > > Notice the additional call to the BaseClass(int) constructor. > > How can I tell swig to insert BaseClass(a) there? Matthias, no-one has had the misfortune of using virtual inheritance and directors, so this problem of the most derived class (director class) having to initialise the virtual bases hasn't come up. So consider it unsupported for now. I'm afraid I can't think of any way to work around it either without hacking the SWIG source. See classDirectorConstructor() in python.cxx for where this code is generated. I havn't given this too much thought, but I suspect there is no way that this initialisation can be generated automatically and so a feature of some sort to manually add in the extra base initialisations is probably necessary. And the reason why multiple inheritance is full of pitfalls and normally avoided is probably becoming clearer... William ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Re: Python, virtual inheritance and directorsAm 01.11.2009, 21:29 Uhr, schrieb William S Fulton
<wsf@...>: > Nitro wrote: >> Hello, >> >> suppose I have two classes like this and turn on directors for the >> derived >> one: >> >> class BaseClass >> { >> BaseClass(int a); >> }; >> >> class MyClass : virtual public BaseClass >> { >> public_ >> MyClass( int a ); >> }; >> >> %feature("director") MyClass; >> >> The code swig will generate looks like >> >> SwigDirector_MyClass::SwigDirector_MyClass(PyObject *self, int a): >> MyClass(a), Swig::Director(self) >> { ... } >> >> This fails to compile, because it should look like >> >> SwigDirector_MyClass::SwigDirector_MyClass(PyObject *self, int a): >> MyClass(a), BaseClass(a), Swig::Director(self) >> { ... } >> >> Notice the additional call to the BaseClass(int) constructor. >> >> How can I tell swig to insert BaseClass(a) there? > > Matthias, no-one has had the misfortune of using virtual inheritance and > directors, so this problem of the most derived class (director class) > having to initialise the virtual bases hasn't come up. So consider it > unsupported for now. I'm afraid I can't think of any way to work around > it either without hacking the SWIG source. See > classDirectorConstructor() in python.cxx for where this code is > generated. I havn't given this too much thought, but I suspect there is > no way that this initialisation can be generated automatically and so a > feature of some sort to manually add in the extra base initialisations > is probably necessary. Thanks for your response, William. I've worked around this problem by now, so swig doesn't see the virtual base class. > And the reason why multiple inheritance is full of pitfalls and normally > avoided is probably becoming clearer... Yes, I'm not a huge fan of it either. It's useful in limited contexts though. C++ is imperfect in quite some places for my purposes anyway, that's why I am wrapping code to Python :-D -Matthias ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
| Free embeddable forum powered by Nabble | Forum Help |