boost: return pointer to base class

John Hunter jdhunter at nitace.bsd.uchicago.edu
Fri Jul 26 10:53:39 EDT 2002


>>>>> "Jacek" == Jacek Generowicz <jacek.generowicz at cern.ch> writes:

    Jacek> 1) Expose a C++ class hierarchy to python (using Boost)

    Jacek> 2) Allow all the exposed classes to be subclassed, with
    Jacek> correct overriding of virtual fuctions

    Jacek> 3) Expose a C++ function which returns a pointer to the
    Jacek> base class.

In general, returning passing raw pointer in boost::python is
problematic.  Have you read
http://www.boost.org/libs/python/doc/pointers.html?

I was able to compile your code by replacing the raw pointer return
with a shared pointer.  Will this suit your needs?

#include <boost/shared_ptr.hpp>

boost::shared_ptr<abstract> rcbpta() {
  return boost::shared_ptr<abstract>(new concrete());
}


John Hunter



More information about the Python-list mailing list