[C++-sig] How do I wrap virtual methods (solved)

Eric Jardim ericjardim at gmail.com
Fri Aug 5 22:25:20 CEST 2005


2005/8/5, David Abrahams <dave at boost-consulting.com>:
> 
> It doesn't. QObject_Wrapper is only needed when the virtual function
> might be overridden in Python. By the time you have a native QObject,
> all of its class' virtual functions are already determined.
> 

Sure, but how does Boost.Python knows that I am exposing QObject? I am 
exposing a derived class of it (QObject_wrapper). Someway, it knows that, 
implicitly, QObject must me exposed too.

I created a function for test this:
QObject* 
factory(QObject* parent)
{
 return new QObject(parent);
}

And later:
def("factory", 
factory, 
return_value_policy<manage_new_object, 
with_custodian_and_ward_postcall<0,1> >());

But how does it will manage this, is I am holding shared pointer to an 
QObject_Wrapper? 
 class_<QObject_Wrapper,
boost::shared_ptr<QObject_Wrapper>,
boost::noncopyable>
("QObject")

I tried to change the pointer to a boost::shared_ptr<QObject> but it did't 
worked. 

But somehow, it is working with the wrapper pointer. There may be some 
"magic" behing the templates :)

And the good news is that there is no need to create the QCustomObject class 
:)

Thanks again,

[Eric Jardim] Boost.Python new fan!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050805/67650301/attachment.htm>


More information about the Cplusplus-sig mailing list