Cython文檔shows如何用重載的方法聲明現有的C++類。cppclass Cython/C++定義中的重載是否被破壞?
但是,如果我定義我自己cppclass
與重載的方法...
cdef cppclass point:
float x, y
point():
this.x = 0
this.y = 0
float sum():
return this.x + this.y
float sum(int z): # COMPILE ERROR
return this.x + this.y + z
...我得到
函數簽名不匹配先前的聲明
重載構造函數給出了相同的錯誤:
cdef cppclass point:
float x, y
point():
this.x = 0
this.y = 0
point(float X, float Y): # COMPILE ERROR
this.x = X
this.y = Y
float sum():
return this.x + this.y
我這樣做是不正確的,還是這個功能缺失?
更新:默認參數似乎是不可用太:
cdef cppclass point:
float x, y
point(float X=0, float Y=0):
this.x = X
this.y = Y
float sum():
return this.x + this.y
cdef float use_point():
cdef point p
p = point(1, 2)
return p.sum()
...通過用Cython,但得到由C++編譯器( 「錯誤的參數數目」)
你有沒有嘗試在構造函數的末尾添加''',除了+'''以查看是否有任何異常因構造函數而發生? – Crt
也許更改其中一個功能的名稱,因爲它們具有相同的名稱 – Crt
*它們具有相同的名稱* - 超載 – MaxB