5
我有一個C++類,它有下面的方法:升壓::蟒串兌換特性
class Bar {
...
const Foo& getFoo() const;
void setFoo(const Foo&);
};
其中類Foo
可以轉換爲std::string
(它具有來自std::string
隱式構造和std::string
轉換運算符)。
我定義一個Boost.Python的包裝類,其中,除其他事項外,定義了基於先前的兩個函數的屬性:
class_<Bar>("Bar")
...
.add_property(
"foo",
make_function(
&Bar::getFoo,
return_value_policy<return_by_value>()),
&Bar::setFoo)
...
我也將類標記爲可轉換到/從std::string
。
implicitly_convertible<std::string, Foo>();
implicitly_convertible<Foo, std::string>();
但在運行時我仍然得到一個轉換錯誤試圖訪問該屬性:
TypeError: No to_python (by-value) converter found for C++ type: Foo
如何實現無包裝的功能太多樣板的轉換? (我已經在Foo
類中的所有轉換功能,所以重複是不可取的。