我正在使用 SWIG 从 Python 访问 C++ 代码。我如何优雅地包装一个函数,该函数在通过引用传递的变量中返回值,例如
void set(double&a) {
a = 42.;
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何做到这一点。在最好的情况下,我可以在 Python 中使用带有 Python 浮点数的函数:
>>> b = 2.
>>> set(b)
>>> print b
42.0
Run Code Online (Sandbox Code Playgroud)
目前它给了我一个TypeError: in method 'TestDouble_set', argument 2 of type 'double &'.