[C++-sig] boost.python - C++ class overridden in python causes slicing
Jean-Sébastien Guay
jean-sebastien.guay at cm-labs.com
Wed Sep 9 04:41:07 CEST 2009
Hi all,
I found an post from earlier this year to this list where David Abrahams
said:
--------------------
If you want to pass an object by reference to a python function, you
have to wrap it in boost::ref(). Otherwise, it will try to copy the
object and the resulting copy will have to be destroyed after the call.
--------------------
http://mail.python.org/pipermail/cplusplus-sig/2009-February/014251.html
This made me think that perhaps the problem was that the object was
being copied, which will of course only copy according to the static type.
And yes, wrapping the arguments to call_method in boost::ref() fixes the
problem! Yay!
And in fact, this fixed the problem for NodeCallback as well. In that
case though, the argument is a pointer:
void operator()(Node* node, NodeVisitor* nv)
{
try {
call_method<void>(self, "call", boost::ref(node),
boost::ref(nv));
}
catch (error_already_set) {
NodeCallback::operator()(node, nv);
}
}
so I don't understand why a copy is being made by call_method, but hey,
it works so I'm happy...
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
More information about the Cplusplus-sig
mailing list