简体   繁体   English

如何在Cython中声明指针向量?

[英]How to declare a vector of pointers in Cython?

I want to declare something like that: 我想宣布这样的事情:

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

But Cython gives me this error: 但是Cython给了我这个错误:

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

mod.pyx:77:20: Expected an identifier or literal

You shouldn't need the * -- vector[Node] should generate code for a vector of Node pointers. 你不应该需要* - vector[Node]应该为Node指针的向量生成代码。 Using Cython 0.14.1: 使用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 the C++ code: 生成C ++代码:

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);

Taking the answer from this SO answer , what you should do is 这个答案回答 ,你应该做的是

ctypedef Node* Node_ptr

and then use Node_ptr across your program. 然后在整个程序中使用Node_ptr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM