¿ÂÃÍ <[EMAIL PROTECTED]> writes:

> Hi:
>
> I  have a question, if my base class has a clone pure virtual function,what can I do 
>to write
> the wrap class?
>
>    struct Base
>     {
>         virtual int f() = 0;
>         virtual Base* clone() = 0;
>     };
>
>     struct BaseWrap : Base
>     {
>         BaseWrap(PyObject* self_)
>             : self(self_) {}
>         int f() { return call_method<int>(self, "f"); }
>         Base* clone(){ return call_method<Base*>(self, "clone");}
>         PyObject* self;
>     };
>
> If I write it like this,it report compile error.

There's nothing wrong with the class declarations shown above, in and
of themeselves. They compile just fine for me.

However, I doubt you want the clone method you've got there. What will
happen, assuming your derived Python class creates a new object in its
clone() override, is that the Python object which holds your BaseWrap
object will have only a single reference count, and to avoid returning
you a dangling pointer, call_method<> will raise a Python exception.

We're currently investigating ways to make your BaseWrap class be /the
same as/ the wrapping Python object, so that their lifetimes will
always be tied together. We hope to have a solution later this week.

-- 
                       David Abrahams
   [EMAIL PROTECTED] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to