On Fri, Sep 9, 2016 at 6:27 AM, Hannes Ovrén <
kig...@gmail.com> wrote:
> Hi!
>
> Thanks for the quick reply, and fix!
>
> How should the baseclass pointer be declared in Cython?
> It should be able to accomodate both Foo<double> and Bar<double> subclasses.
> I admit that I am not really sure how I would do this in C++ either.
The only way to do this is to have a superclass of Base that is not
templatized on Derived (in C++ or Cython).
> Also, my subclasses have some methods of their own, which are not shared,
> which we can call
> Foo::do_foo() and Bar::do_bar() that need to be exposed by the Python
> wrapper class.
> I guess I can solve this by casting the base pointer like this:
>
> class PyFoo(Base):
> ...
>
> def foo(self):
> return (<classes.Foo[double]*> self.wrapped).do_foo()
Yes, you have to do a cast. If it makes life easier, you could store a
copy to the specialized pointer in your subclass, e.g
class PyFoo(Base):
cdef Foo* foo_ptr
def __init__(self, ...):
super(PyFoo, self).__init__(...)
self.foo_ptr = <classes.Foo[double*]> self.wrapped
def foo(self):
return foo.do_foo()
> On Friday, September 9, 2016 at 9:48:19 AM UTC+2, Robert Bradshaw wrote:
>>
>> On Thu, Sep 8, 2016 at 4:48 AM, Hannes Ovrén <
kig...@gmail.com> wrote:
>> > I am trying to wrap a set of C++ classes with Cython which are using the
>> > curiously recurring template pattern (CRTP) but I can't seem to get
>> > Cython
>> > to accept wrapping it.
>> >
>> > Am I declaring the subclasses wrong in the PXD-file, or is Cython
>> > currently
>> > unable to handle this kind of CRTP-style self templating?
>> >
>> > Any help regarding this is most welcome. Thanks!
>>
>> This was unsupported, fixed at
>>
>>
https://github.com/cython/cython/commit/1f98bcd70568049442e4fe8e513113032166257a
>> .
>>
>> Note, however, you can't declare a pointer to the untemplated Base
>> type (there isn't such a type in C++, though you could give it a base
>> and put the calculate method there). Of course this is probably just
>> an oversimplification of the real code...
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
cython-users...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.