[C++-SIG] Re: CXX3 extending with C++ classes

Paul F. Dubois dubois1 at llnl.gov
Wed Jul 21 18:01:21 CEST 1999


Something got lost here. What is b?

However, perhaps m = a[1] and then you are using m as an argument? I suspect
I know the problem.

CXX uses a proxy class for the result of a[1] since you don't know at the
time of subscripting whether this is a LHS or RHS use. This class has a
user-defined conversion to the type of the sequence so when you use it in an
expression or as a rhs of an assignment it casts itself, and the cast
performs the actual "fetch".

Most of the time proxy objects are suitably invisible but the fact is that
they have a different type than the one you think they do and that could
cause trouble when mixed with C++'s elaborate rules for automatic casts. The
solution is to make the cast explicit, eg.
m = Object(a[1])
(or whatever class you really think a[1] is).

Proxys are discussed in Scott Meyer's books although the version I had to
use was somewhat more elaborate.
See the code in Sequence for details.

Hope this helps,

Paul

----- Original Message -----
From: Marc POINOT <poinot at onera.fr>
To: Paul F. Dubois <dubois1 at llnl.gov>; <c++-sig at python.org>
Sent: Wednesday, July 21, 1999 6:03 AM
Subject: CXX3 extending with C++ classes


>
> I have some problem with CXX extension. I think I have
> to learn more about Python extensions in general, but
> maybe some pythoner can help me faster ...
>
> In have succedeed in extending Python with some
> of our C++ classes (using CXX3).
> Now, I want to build extended-objects with other
> extended-objects as args. Here's a piece of the Python
> part of the code:
>
> import example
>
> v="x y z"
> f="file.mai"
>
> # First extended class
> a=example.EpyBlkMesh(45,17,17,v,f)
>
> # ok
> print type(a)
>
> # ok
> m=b[1]
> print type(m)
>
> # Second extended class using first one
> c=example.EpyGeoGrid(m)
>
> # never get here, it failed before
> c.volume()
>
> ------
> The point is, when I look at the pointer adress of m,
> it is different of the one I have for a.
> My function EpyGeoGrid_new(PyObject *self, PyObject *args)
> seems to have an args type which cannot be cast
> to EpyGeoGrid...
>
> Any tip?
> Any doc reference?
>
> Marcvs [alias I didn't found such example in r.cxx Demo...]
>
>
>
>





More information about the Cplusplus-sig mailing list