[C++-sig] How do I wrap virtual methods
Eric Jardim
ericjardim at gmail.com
Fri Aug 5 15:33:26 CEST 2005
Hi,
I am wrapping a library, and everything is going well. But now I am trying
to wrap some virtual methods.
After that a strange behavior is happening (I am using boost 1.32). I am
using Pyste to wrap a "scratch code" for me, and I then manually insert some
wrapped functions/classes/enums to the definitive source. (This approach
might be strange, but it is good for me. It helps me learning
Boost.Pythonconstructs, and it's a way to control errors for each
step.)
The error consist basically of a wrapped virtual method of the "QObject"
class being called *without* it being reimplemented in Python. Of course it
was reimplemented in C++, when the "QObject_Wrapper" class was created.
Pyste is generating the "QObject_Wrapper" with the overloaded constructors,
a "PyObject* py_self" reference to the Python object, everything explicit!
On the other hand, I saw on the tutorial that you should use a construct
like:
struct BaseWrap : Base, wrapper<Base>
{
int f()
{
if (override f = this->get_override("f"))
return f(); // note*
return Base::f();
}
int default_f() { return this->Base::f(); }
};
// *note: on MSVC use
// return call<char const*>(f.ptr());
I think that this will solve the problem, because it tests if there is a
overriden method. I am still confused if wrapper<...> will create the
apropriate contructors. So what do "wrapper<..>" really do?
Another thing that I noticed is that I have to reimplement virtual methods
on every derived class. This is an accumulative task. Am I right?
So, what is the right and safe way to wrap virtual methods?
Thanks,
[Eric Jardim]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050805/7b519405/attachment.htm>
More information about the Cplusplus-sig
mailing list