Reputation: 3205
I'm trying to get a reference to a object in cython. The following code compiles without problems:
cdef vector[int] a
a.push_back(1)
cdef vector[int] & b=a
However, as I add the following line:
b.push_back(1)
The compiler complains that b has been declared as a reference but not initialized. How should I initialise a reference in cython? (the documentation is a bit vague on the usage of references in cython)
Upvotes: 4
Views: 462
Reputation: 10262
Why not doing this :
cdef vector[int] a
a.push_back(1)
cdef vector[int] *b=&a
b[0].push_back(1)
b.push_back(2) # Works too, I gess
Upvotes: 4