简体   繁体   English

在函数定义之后将返回对象分配给函数名称的目的

[英]Purpose of assigning the return object to the function name after the function definition

I find the generated Python wrapper for a C++ function by swig has the following lines: 我发现swig为C ++函数生成的Python包装器包含以下几行:

def my_func(arg):
    return _cpp_mod.my_cpp_func(arg)
my_func = _cpp_mod.my_cpp_func

The source code in the .i file is as follows: .i文件中的源代码如下:

%module cpp_mod
... ...
%inline %{
MyObj& my_cpp_func(arg) {
    return *new MyObj(arg);
}
%}

All functions of the generated code seem OK. 生成的代码的所有功能似乎都正常。
What I want to know is the purpose of the third line for the 我想知道的是第三行的目的
generated python code. 生成的python代码。 Thanks in advance. 提前致谢。

It just the way SWIG has decided to wrap functions. 这正是SWIG决定包装功能的方式。 The first part 第一部分

def my_func(arg):
  return _cpp_mod.my_cpp_func(arg)

reveals the number of input arguments and if commments are generated, they will be inserted here. 显示输入参数的数量,如果生成了注释,则将它们插入此处。

The second part 第二部分

my_func = _cpp_mod.my_cpp_func

is redefining the function to the generated library function 正在将函数重新定义为生成的库函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM