Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-03-23 18:55:16

> -----Original Message-----
> From: Phlip [mailto:pplumlee_at_[hidden]]
> Proclaimed David Abrahams from the mountaintops:
> > > -----Original Message-----
> > > From: Karl Bellve [mailto:Karl.Bellve_at_[hidden]]
> > >
> > > I am still having some issues with using Boost, Python and C++.
> > >
> > > I want to be able to export a specific instance of a class to Python.
> > > I don't want to load a new instance of the class inside Python. Is
> > > this possible?
> >
> > What does "load a new instance of the class inside Python" mean? I don't
> > think I can answer your question unless you use terms I can understand.

Thanks for posting this, Philip. A second brain is sometimes a big help!

> He needs something like this:
> auto_ptr<class> function () {
> return new class;
> }
> The difference is C++ constructs the object, not Python.

OK, if we understand him correctly, then let me correct your code. The
std::auto_ptr constructor is explicit, so:

std::auto_ptr<my_class> function() {
        return std::auto_ptr<my_class>(new my_class);

> I spawned a thread asking this question many moons ago. The OP is advised
> to Google for my distinctive street name

Street Name? Is this some internet lingo to which I'm unprivy?

The thread is here:

> and auto_ptr and shared_ptr to
> learn the tricks and traps here. I recall that the 'build_class<>' or
> whatever template must appear above a function like this or else
> 'to_python' won't find enough traits to go on.

Philip has the concepts right, but missed on some of the details. The issue
is that class_builder<my_class> [1] must be used before you call
def(function) [2]:

boost::python::module_builder m("my_module");
boost::python::class_builder<my_class> builder(m, "my_class"); // 1
m.def(function, "function"); // 2


Boost list run by bdawes at, gregod at, cpdaniel at, john at