Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-11-03 09:18:49


----- Original Message -----
From: "Anton Gluck" <gluc_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, November 03, 2000 12:35 AM
Subject: Re: [boost] py_cpp: vc6_prj and version 10-31

> Dave,
>
> > In general, py_cpp doesn't automatically convert pointer return values
> > to_python because pointers have too many potential meanings. Is it an
> > iterator? A pointer to a single element? An array? Is ownership being
passed
> > to Python or is the pointer really just a reference? If the latter, what
> > happens when some C++ code deletes the referent. The only exception to
this
> > rule is const char*, since it has a generally accepted interpretation
(could
> > be trouble with some generic code, though!)
> >
> > If you have wrapped the Record class, you could add this to namespace
py:
> >
> > PyObject* to_python(const Record* p) {
> > return to_python(*p);
> > }
>
> I have Record wrapped already (its constructor and one of its functions),
> but when I add the above code I'm getting this error:
>
> error C2665: 'to_python' : none of the 20 overloads can convert parameter
> 1 from type 'const class Record'
>
> Did I put this code into the wrong spot (it's in namspace py, in the same
> area where the from_python code is that deals with enumerations,
> i. e. before initClusterForPy() which wrapps Record)?

Yes. As the documentation at
http://people.ne.mediaone.net/abrahams/downloads/under-the-hood.html says,

  "Because the to_python and from_python functions for a user-defined class
are defined by ExtensionClass<T>, it is important that an instantiation of
ExtensionClass<T> is visible to any code which wraps a C++ function with a
T, T*, const T&, etc. parameter or return value. In particular, you may want
to create all of the classes at the top of your module's init function, then
def the member functions later to avoid problems with inter-class
dependencies."

the missing information is that ExtensionClass<T>is instantiated by
ClassWrapper<T>. Your use of to_python(const Record&) is dependent on a
previous instantiation of ExtensionClass<Record>. You can explicitly
instantiate ExtensionClass<Record> as follows:

template class py::ExtensionClass<Record>;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk