[Pyrex] C++ issue

Robert Bradshaw robertwb at math.washington.edu
Mon Apr 28 19:09:11 CEST 2008


In this case you might want to declare your variable to be *pointers*  
to the given classes, rather than the classes themselves. This will  
prevent c++ from trying to create them directly where the are  
declared (though you will then have to manually delete them when  
you're done with them).

- Robert

On Apr 28, 2008, at 9:26 AM, Ravi Lanka wrote:
> Pyrex gurus,
>
>   I am trying to wrap a C++ library and have been successful for the
> most part (thanks to you guys).  One of the classes that I need to  
> wrap
> does not contain a default constructor (see code below ).  The cpp  
> file
> that gets created complains that "foo" does not contain a default
> constructor [ cdef foo f  is invalid ].  At the same time, I cannot  
> say
> "cdef foo f = b.getFoo()". My solution was to build the cpp file from
> the pyrex code below and then create a line that says;
>
> cdef foo f = b.getFoo() instead of  "f = b.getFoo",
>
> and remove the initial declaration.  It works for what I am doing,  
> but I
> am afraid that there could be some reference count issues.
> Unfortunately, the argument required by the constructor of foo  
> class is
> neither required nor available in my wrapper code.
>
> Any Ideas ?
> thanks in advance.
>
> Ravi
>
> ------------------
> class foo {
>     public:
>         foo( templatedClassObject  unAvailable );
>         int (*getItems) { return 1; }
> };
>
> class bar {
>     public:
>         bar();
>         foo& getFoo() { return fooObj; }
> };
>
> pyrex:
>
> cdef extern from "foo.h":
>     ctypedef struct foo "foo":
>         int (*getItems)()
>
> cdef extern from "bar.h":
>     ctypedef struct bar "bar":
>         foo (*getFoo)()
>
>     bar *barFactory "new bar"()
>     void deleteBar "delete "(bar *barObj)
>
> def test():
>     cdef    bar   b
>     cdef    foo   f
>     ### b is populated through some calculations here
>     f = b.getFoo()
> -------------------------
>
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex




More information about the Pyrex mailing list