[C++-sig] Re: Virtual Functions with Default Implementations code sample

David Abrahams dave at boost-consulting.com
Mon Jul 28 15:59:01 CEST 2003


"Alex" <alex at glumol.com> writes:

> I can't build the "Virtual Functions with Default Implementations" code
> sample from the online tutorial :
>
> struct Base
>     {
>         virtual int f() { return 0; }
>     };
>
> struct BaseWrap : Base
>     {
>         BaseWrap(PyObject* self_)
>             : self(self_) {}
>         int f() { return call_method<int>(self, "f"); }
>         int default_f() { return Base::f(); } // <<=== ***ADDED***
>         PyObject* self;
>     };
>
> -------
>
> class_<Base, BaseWrap>("Base")
>         .def("f", &Base::f, &BaseWrap::default_f)
>
>
> --> get the error "value_holder.hpp(131) : error C2661: 'BaseWrap::BaseWrap'
> : no overloaded function takes 2 parameters"


This is a tutorial bug.

We need to either:

   1. Add a copying constructor:

              BaseWrap(PyObject* self_, Base const& rhs)
                 : Base(rhs), self(self_) {}

   2. Use noncopyable in the wrapper:

        class_<Base, BaseWrap, noncopyable>("Base")
            .def("f", &Base::f, &BaseWrap::default_f)
            ;


[Joel, could you choose an appropriate fix?]

> (btw I can build all the other code samples from the tutorial)

That's a relief!

> -------
>
> other newbie questions :
>
> Is there a place on the web where all the c++-sig at python mails are archived
> ?

http://www.boost.org/more/mailing_lists.htm#cplussig lists two
archives in addition to http://mail.python.org/pipermail/c++-sig/..

> Does pyste can convert C++ function arguments to python keyword arguments ?

I don't think so; IIRC GCC_XML doesn't give us the declared argument
names (if any).  Nicodemus?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list