我的C++代碼有這樣的事情:痛飲:在結構和分配自定義類型在Python
struct Data
{
CustomType member;
};
我痛飲.i文件有%類型映射(中)和%類型映射(出)到Python字符串轉換爲從CustomType(這是工作的罰款參數和返回值)
在我的蟒蛇,我這樣做:
d = Data()
d.member = "Hello"
和Python給了我在運行時出現此錯誤: 類型錯誤:方法「Data_member_set」,鍵入「CustomType *」
我嘗試的論點2以下沒有作用:
%typemap(memberin) CustomType
{
$target = *$source;
}
如何讓蟒蛇讓我分配給會員嗎?
因爲CustomType沒有暴露蟒蛇該解決方案並沒有爲我工作 - 在Python我們只使用了Python海峽型。用str(...)替換CustomType(...)不起作用。 – njaard
@njaard那麼你期望能夠分配給它嗎? – Schollii
我期望它從python str轉換,就像我將str作爲參數傳遞給接受CustomType的函數一樣 – njaard