最近在用 pybind11 绑定 c++中的一个库到 Python 中,遇到了一个问题
待绑定的类方法如下
class Ciphertext
{
public:
inline auto &scale() noexcept
{
return scale_;
}
inline auto &scale() const noexcept
{
return scale_;
}
private:
double scale_ = 1.0;
}
其例子中,有这样的调用:
Ciphertext x1_encrypted
x1_encrypted.scale() = pow(2.0, 40)
我是这样绑定的,可以成功访问到 scale 的值:
py::class_<Ciphertext>(m, "Ciphertext")
.def("scale", (double &(Ciphertext::*)()) &Ciphertext::scale)
但是,显然不能这样在 python 中给它赋值,请问有什么方法?还是说,只能自己去增加 set 方法?
谢谢各位了!
,谢谢