How to declare a vector of pointers in Keaton?

I want to declare something like this:

cdef vector[Node*] list2node(list my_list):

But Cython gives me this error:

cdef vector[Node*] list2node(list my_list):
                ^
------------------------------------------------------------

mod.pyx:77:20: Expected an identifier or literal
+3
source share
2 answers

You do not need to *- vector[Node]must generate code for the Node pointer vector. Using Cython 0.14.1:

cdef class Node: 
    pass
cdef vector[Node] list2node():
    pass
cdef vector[int] test_int():
    pass
cdef vector[int*] test_intp(): 
    pass

Generates C ++ code:

static PyTypeObject *__pyx_ptype_3foo_Node = 0;
static std::vector<struct __pyx_obj_3foo_Node *> __pyx_f_3foo_list2node(void);
static std::vector<int> __pyx_f_3foo_test_int(void);
static std::vector<int *> __pyx_f_3foo_test_intp(void);
+5
source

Taking the response from this SO answer you need to do

ctypedef Node* Node_ptr

and then use Node_ptrin your program.

+1
source

All Articles