[C++-sig] Re: Problem With Calling Methods on Python Subclasses from C++
David Abrahams
dave at boost-consulting.com
Sun Oct 17 17:33:07 CEST 2004
Mark Rowe <lists.python.org at bdash.net.nz> writes:
> class _ErrorHandlerWrapper : public ErrorHandler, public wrapper<ErrorHandler>
> {
> public:
> virtual void handleError(const Error & err) const {
> if (override f = this->get_override("handleError"))
> {
> f(err);
If you want the type of err to be preserved, you have to pass it by
reference:
f(boost::ref(f));
> }
> else
> ErrorHandler::handleError(err);
> }
> };
Boost.Python never passes anything by reference, by default, because
it's unsafe: it can lead to dangling pointers. It would be very
interesting to consider copying and passing whole most-derived class
instances by value, but that's not implemented.
HTH,
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list