Cython & C++: passing by reference Cython & C++: passing by reference python python

Cython & C++: passing by reference


Found the answer to my own question. Apparently, you can pass by reference, but the function MUST be cdef'ed, not def'ed. i.e.

# somefile.pyx#distutils: language = c++from libcpp.vector cimport vectorcdef void add_one(vector[int]& vect):    cdef int i    n = vect.size()    for i in range(<int>n):        vect[i] += 1cdef vector[int] vfor i in range(100000):    v.push_back(i)add_one(v)