传递给用swig包装的重载c++构造函数的参数数量/类型有问题

2024-10-01 15:49:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用swig包装一个由其他人用swig编写的c++类(我们称之为“Spam”),将其公开给Python。 在解决了几个问题之后,我可以用python导入模块,但是当我试图创建一个此类的对象时,我得到了以下错误:

 foo = Spam.Spam('abc',3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Spam.py", line 96, in __init__
    this = _Spam.new_Spam(*args)
NotImplementedError: Wrong number of arguments for overloaded function 'new_Spam'.
  Possible C/C++ prototypes are:
    Spam(unsigned char *,unsigned long,bool,unsigned int,SSTree::io_action,char const *)
    Spam(unsigned char *,unsigned long,bool,unsigned int,SSTree::io_action)
    Spam(unsigned char *,unsigned long,bool,unsigned int)
    Spam(unsigned char *,unsigned long,bool)
    Spam(unsigned char *,unsigned long)

通过搜索,我意识到错误可能是由参数类型引起的,而不是由数字引起的(这非常令人困惑),但我仍然无法确定。我怀疑问题在于传递一个字符串作为第一个参数,但不知道如何修复它(请记住,我几乎不知道c/c++)。在


Tags: inionew错误lineactionspamlong
3条回答

SWIG将字符串视为“char*”。您使用“unsigned char*”很可能会混淆它。您可以将签名更改为“char*”或提供类型映射:

%typemap(in) unsigned char * = char*

这可以通过修改行100到110来解决

self.source = uhd_receiver(options.args, symbol_rate,
                                   options.samples_per_symbol,
                                   options.rx_freq, options.rx_gain,
                                   options.spec, options.antenna,
                                   options.verbose)

        self.sink = uhd_transmitter(options.args, symbol_rate,
                                    options.samples_per_symbol,
                                    options.tx_freq, options.tx_gain,
                                    options.spec, options.antenna,
                                    options.verbose)

到下面

^{pr2}$

祝你好运

尝试使用:

%typemap(in) (unsigned char *) = (char *);

相关问题 更多 >

    热门问题