我需要一個使用 Cython 擴展型別的鏈表,即。cdef class但是 Cython 編譯器抱怨 Python 物件。
cdef class Item:
cdef Item* prev
cdef Item* next
Cython 錯誤: Pointer base type cannot be a Python object
這cdef struct只是使用的任何解決方法cdef class?(因為我需要方法和 OOP 約定)
uj5u.com熱心網友回復:
cdef class 就像任何其他 Python 物件一樣,通過參考存盤/傳遞。
這意味著這里沒有必要使用指標:內部表示已經用指標存盤了。因此只需使用cdef Item.
與任何其他 Python 物件一樣,您Item將被參考計數,并在不存在其他參考時自動重新分配。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/349716.html
