[C++-sig] Constructors in callback classes.

David Abrahams dave at boost-consulting.com
Sat Nov 9 04:51:08 CET 2002


"Brett Calcott" <brett.calcott at paradise.net.nz> writes:

> Hi,
>
> Callback classes look like this:
>
>    class py_agent : public agent
>    {
>    public:
>       py_agent(PyObject* self) : m_self(self) {}
>
>       char const *do_something() const
>       {
>          using namespace boost::python;
>          return call_method<char const*>(m_self, "do_something");
>       }
>
>       PyObject* const m_self;
>
>    };
>
> But what if the parent class "agent" has no default constructor. Can
> I pass through arguments as well as the PyObject * ?

Yes, in fact, you should.

> It wasn't obvious what I should do here.

Good point. I need to add a note in
  http://www.boost.org/libs/python/doc/v2/class.html#HeldType
and Joel should add something in
  http://www.boost.org/libs/python/doc/tutorial/doc/class_virtual_functions.html

Thanks for pointing it out.
-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list