Question about C++ references

42 views
Skip to first unread message

Charanpal Dhanjal

unread,
Apr 19, 2012, 3:25:29 PM4/19/12
to cython...@googlegroups.com
Hi all,

I am trying to wrap some C++ code in Cython and am having trouble with references. Here is a code snippet:

cdef extern from "mapped_matrix_ext.h":

cdef cppclass mapped_matrix_ext[T]:

mapped_matrix_ext(int, int, int)

mapped_matrix_ext[T]& add(mapped_matrix_ext[T]&)

cdef mapped_matrix_ext[double] *A = new mapped_matrix_ext[double](3, 3, 5)

cdef mapped_matrix_ext[double] *B = new mapped_matrix_ext[double](3, 3, 5)
cdef mapped_matrix_ext[double] *C

C = A.add(deref(B))


I get the error "Cannot assign type 'mapped_matrix_ext<double> &' to 'mapped_matrix_ext<double> *'" for the last line which I think means that I need to find the reference of the value returned by the add method. I wasn't able to find how to do this in the documentation however (I think it's meant to be in "Declaring/Using References" which hasn't yet been written). Could someone please help me out?

Thanks for any help,
Charanpal

Bradley Froehle

unread,
Apr 20, 2012, 11:21:37 AM4/20/12
to cython...@googlegroups.com
You have defined "add" to return a reference (mapped_matrix_ext[T]&) but are assigning the result to a pointer (mapped_matrix_ext[double]*).

Charanpal Dhanjal

unread,
Apr 20, 2012, 2:48:54 PM4/20/12
to cython...@googlegroups.com
Thanks. Sorry if this is a silly question - is there a simple way I can convert the reference into a pointer?
Charanpal
Reply all
Reply to author
Forward
0 new messages