[C++-sig] call_method

David Abrahams dave at boost-consulting.com
Thu Nov 7 14:03:56 CET 2002

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

> Hi all,
> Firstly, thanks for the funky library - Dave and others. I am
> looking forward to making my development go a lot faster by
> scripting most of it and leaving just the core in c++.
> I somewhat overwhelmed by the sophistication of the methods involved
> to make this thing work so elegantly - so I am grappling to
> understand how to make it do what I want. (Likely that I should do
> what *it* wants..)

The idea is for it to go the other way... :(

> First up - a documentation bug (if you haven't already found it). I have the
> download from boost.org - not CVS and I see this in call_method.html
> // Callback class
> class Base_callback : public Base
> {
>  public:
>    Base_callback(PyObject* self) : m_self(self) {}
>    char const* class_name() const { return call_method(m_self,
> "class_name"); }
>                                            ^^^^^^^^^^^^^^
>    char const* Base_name() const { return Base::class_name(); }
>  private:
>    PyObject* const m_self;
> };
> That should be:
>    char const* class_name() const { return call_method<char const*>(m_self,
> "class_name"); }
> Right? That had me fooled for a bit.

Right. Thanks, fixed in CVS.

> Now the problem:

> But to use class_ on it I need to create another shared_ptr for the
> py_agent,
> typedef boost::shared_ptr<py_agent> py_agent_ptr;
> and then this:
> class_<agent, bases<>, py_agent_ptr, boost::noncopyable>("py_agent")
>   .def("do_something", &py_agent::do_something)
>    ;
> But now, I can't add a py_agent using the python exported "add_agent"
> function, as it is not the right type.

Have you tried adding a call to 



> I am used to using shared_ptr in vectors for containing derived types - so,
> as in this case, the engine can call "do_something" on all of them and they
> can all "do their thing". How, if at all, can I get this happening here...

I now have quite a pile of polymorphism-related feature requests
pending, so please let me know if the above doesn't solve your
problems. I'll add this to the list of things to address.

                    David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com

More information about the Cplusplus-sig mailing list