[C++-sig] call_method

Tim Field nobbis at mcs.vuw.ac.nz
Sat Nov 9 22:10:10 CET 2002


On Sun, 2002-11-10 at 00:59, Brett Calcott wrote:

<snip>

> The next one returns with a C++ runtime exception error
> Debugging the code it looks as if the m_self member that is held in the
> callback class has been deleted - causing the crash.

Hey Brett,

My (relatively uninformed) guess is that the inheritance/call-back issue
is a red herring -- I think the agent is getting garbage-collected
before you call 'do_something' on it.  I reckon you should just replace

  .def("add_agent", &engine::add_agent)

with

  .def("add_agent", &engine::add_agent, with_custodian_and_ward<1, 2>())

so that the lifetime of the agent object is linked to that of the
engine.  I could be wrong, of course (has been known to happen)...


Hope that helps,
Tim






More information about the Cplusplus-sig mailing list